1 Study 1: In-lab ORXOR

2 Study 2: Online ORXOR

df.total.valid.2 <- read.csv('../Data/Study1/online/Study1b_1.csv')
df.rating.2 <- read.csv('../Data/Study1/online/Study1b_2.csv')

df.rating.2.summary <- df.rating.2 %>% group_by(participant) %>%
  summarise(medianValue=median(value),
            avgValue=mean(value)) %>% ungroup()

3 Study 3: Online ORXOR-D

df.total.valid.3 <- read.csv('../Data/Study2/Study2_1.csv')
df.rating.3 <- read.csv('../Data/Study2/Study2_2.csv')

df.rating.3.summary <- df.rating.3 %>% group_by(participant) %>%
  summarise(medianValue=median(value),
            avgValue=mean(value)) %>% ungroup()

4 Apply exclusion criteria

Study 2 and 3: matched with study 1 regarding the likelihood of opposite actions

df.total.rt.12 <- rbind(df.total.rt.1 %>% dplyr::select(-sex) %>% mutate(study='S1',
                                                                  participant=as.character(participant)),
                        df.total.rt.2 %>% mutate(study='S2')) %>%
  dplyr::mutate(scaledMeanValue=scale(meanValue),
                scaledValueDiff=scale(valueDiff),
                scaledTrialNum=scale(trialN),
                catChoiceCondition=relevel(factor(catChoiceCondition),ref='XOR'),
                acc=as.factor(isBestFirst==1))
df.total.valid.12 <- rbind(df.total.valid.1 %>% dplyr::select(-sex) %>% mutate(study='S1',
                                                                        participant=as.character(participant)),
                           df.total.valid.2 %>% mutate(study='S2')) %>% mutate(study=factor(study)) %>%
  dplyr::mutate(scaledMeanValue=scale(meanValue),
                scaledValueDiff=scale(valueDiff),
                scaledTrialNum=scale(trialN),
                catChoiceCondition=relevel(factor(catChoiceCondition),ref='XOR'))
contrasts(df.total.rt.12$catChoiceCondition)<-contr.sdif
contrasts(df.total.rt.12$acc)<-contr.sdif
contrasts(df.total.valid.12$catChoiceCondition)<-contr.sdif

4.1 Selection Task - Models

model.RT.12 <- lmerTest::lmer(firstRT ~ catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum + 
                     (1 + catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),
                   data=df.total.rt.12)
## boundary (singular) fit: see help('isSingular')
anova(model.RT.12)
## Type III Analysis of Variance Table with Satterthwaite's method
##                                     Sum Sq Mean Sq NumDF   DenDF F value
## catChoiceCondition                  48.243  48.243     1  79.065  53.621
## scaledMeanValue                    203.049 203.049     1  62.011 225.686
## scaledValueDiff                    129.075 129.075     1  64.569 143.464
## scaledTrialNum                      27.156  27.156     1  78.985  30.184
## catChoiceCondition:scaledMeanValue  20.675  20.675     1  64.490  22.980
## catChoiceCondition:scaledValueDiff   0.167   0.167     1 134.058   0.186
##                                       Pr(>F)    
## catChoiceCondition                 1.788e-10 ***
## scaledMeanValue                    < 2.2e-16 ***
## scaledValueDiff                    < 2.2e-16 ***
## scaledTrialNum                     4.646e-07 ***
## catChoiceCondition:scaledMeanValue 1.002e-05 ***
## catChoiceCondition:scaledValueDiff    0.6669    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
model.acc.12 <- glmer(isBestFirst ~ catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff +
                        scaledTrialNum + 
                     (1 + catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff +
                        scaledTrialNum|participant),
                     data=df.total.rt.12,family=binomial,control = glmerControl(optCtrl = list(maxfun=20000)))
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.00987731 (tol = 0.002, component 1)
anova(model.acc.12)
## Analysis of Variance Table
##                                    npar  Sum Sq Mean Sq  F value
## catChoiceCondition                    1   3.538   3.538   3.5377
## scaledMeanValue                       1   0.033   0.033   0.0328
## scaledValueDiff                       1 301.164 301.164 301.1639
## scaledTrialNum                        1   1.803   1.803   1.8033
## catChoiceCondition:scaledMeanValue    1   1.365   1.365   1.3655
## catChoiceCondition:scaledValueDiff    1   1.404   1.404   1.4041
tab_model(model.RT.12,model.acc.12,transform = NULL,show.re.var = F,pred.labels = c("Intercept","Inclusivity","Overall Value","Relative Value","Trial Order","Incl by OV","Incl by RV"),dv.labels = c("RT","Accuracy"))
  RT Accuracy
Predictors Estimates CI p Log-Odds CI p
Intercept 2.72 2.56 – 2.88 <0.001 -0.09 -0.19 – 0.01 0.083
Inclusivity -0.30 -0.38 – -0.22 <0.001 -0.10 -0.19 – -0.01 0.029
Overall Value -0.36 -0.41 – -0.31 <0.001 0.01 -0.06 – 0.08 0.790
Relative Value -0.19 -0.22 – -0.16 <0.001 0.65 0.57 – 0.73 <0.001
Trial Order -0.12 -0.16 – -0.08 <0.001 -0.03 -0.08 – 0.01 0.164
Incl by OV -0.14 -0.20 – -0.08 <0.001 -0.08 -0.19 – 0.03 0.148
Incl by RV 0.01 -0.04 – 0.06 0.666 -0.06 -0.17 – 0.04 0.246
ICC   0.08
N 82 participant 82 participant
Observations 10138 10138
Marginal R2 / Conditional R2 0.158 / NA 0.105 / 0.178
model.acc.12.dummy <- lmer(isBestFirst ~ catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff +
                        scaledTrialNum + 
                     (1 + catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff +
                        scaledTrialNum|participant),
                     data=df.total.rt.12,control = lmerControl(optCtrl = list(maxfun=20000)))
## boundary (singular) fit: see help('isSingular')
model.RT.12.coeff <- lmerTest::lmer(firstRT ~ catChoiceCondition / scaledMeanValue + catChoiceCondition / scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition / scaledMeanValue + catChoiceCondition / scaledValueDiff + scaledTrialNum|participant), 
                   data=df.total.rt.12,
                   control=lmerControl(optCtrl=list(maxfun=1e6)))
## boundary (singular) fit: see help('isSingular')
model.acc.12.coeff <- glmer(isBestFirst ~ catChoiceCondition / scaledMeanValue + catChoiceCondition / scaledValueDiff + scaledTrialNum + 
                     (1 + catChoiceCondition / scaledMeanValue + catChoiceCondition / scaledValueDiff + scaledTrialNum|participant),
                     data=df.total.rt.12,family=binomial)
## boundary (singular) fit: see help('isSingular')
df.total.rt.12.rr <- df.total.rt.12 %>% mutate(rr=firstValue/firstRT) 


model.rr.12 <- lmerTest::lmer(rr ~ catChoiceCondition * (scaledMeanValue + scaledValueDiff) + scaledTrialNum + 
                     (1 + catChoiceCondition * (scaledMeanValue + scaledValueDiff) + scaledTrialNum|participant),
                   data=df.total.rt.12.rr,
                   control=lmerControl(optCtrl=list(maxfun=1e6)))
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 1 negative eigenvalue: -4.2e+02
tab_model(model.rr.12,dv.labels = c('Reward Rate'),pred.labels = c('Intercept','OR - XOR','Mean Value','Value Diff','Trial Num','Incl X Mean Value','Incl X Value Diff'))
  Reward Rate
Predictors Estimates CI p
Intercept 3.31 2.98 – 3.63 <0.001
OR - XOR 0.36 0.24 – 0.48 <0.001
Mean Value 1.34 1.20 – 1.48 <0.001
Value Diff 0.44 0.37 – 0.50 <0.001
Trial Num 0.12 0.01 – 0.23 0.033
Incl X Mean Value 0.26 0.16 – 0.36 <0.001
Incl X Value Diff 0.02 -0.07 – 0.10 0.720
Random Effects
σ2 3.51
τ00 participant 2.20
τ11 participant.catChoiceConditionOR-XOR 0.19
τ11 participant.scaledMeanValue 0.38
τ11 participant.scaledValueDiff 0.04
τ11 participant.scaledTrialNum 0.23
τ11 participant.catChoiceConditionOR-XOR:scaledMeanValue 0.07
τ11 participant.catChoiceConditionOR-XOR:scaledValueDiff 0.00
ρ01 -0.04
1.00
-0.79
-0.10
0.14
0.18
N participant 82
Observations 10138
Marginal R2 / Conditional R2 0.329 / NA
model.conflict.12 <- lmerTest::lmer(conflict ~ catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.valid.12)
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 2 negative eigenvalues: -9.2e-04
## -3.8e-03
tab_model(model.conflict.12,transform = NULL,show.re.var = F,pred.labels = c("Intercept","Inclusivity","Overall Value","Overall Value^2","Relative Value","Trial Order","Incl by OV","Incl by OV^2","Incl by RV"),dv.labels = c("Conflict"))
  Conflict
Predictors Estimates CI p
Intercept 2.39 2.25 – 2.52 <0.001
Inclusivity -0.46 -0.62 – -0.30 <0.001
Overall Value 15.18 4.64 – 25.72 0.005
Overall Value^2 12.79 8.11 – 17.46 <0.001
Relative Value -0.07 -0.10 – -0.03 <0.001
Trial Order 0.01 -0.03 – 0.05 0.723
Incl by OV -18.83 -27.12 – -10.53 <0.001
Incl by OV^2 -4.70 -9.79 – 0.39 0.070
Incl by RV 0.00 -0.04 – 0.05 0.910
N participant 82
Observations 10520
Marginal R2 / Conditional R2 0.124 / NA
df.total.rt.12$scaledRT<-scale(df.total.rt.12$firstRT)

model.conflict.12.rt <- lmerTest::lmer(conflict ~ scaledRT + acc + catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + scaledRT + acc + catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.12)
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 2 negative eigenvalues: -1.8e-03
## -2.0e-02
tab_model(model.conflict.12.rt,transform = NULL,show.re.var = F,pred.labels = c("Intercept","RT","Accuracy","Inclusivity","Overall Value","Overall Value^2","Relative Value","Trial Order","Incl by OV","Incl by OV^2","Incl by RV"),dv.labels = c("Conflict"))
  Conflict
Predictors Estimates CI p
Intercept 2.36 2.23 – 2.50 <0.001
RT 0.09 0.05 – 0.13 <0.001
Accuracy -0.09 -0.13 – -0.05 <0.001
Inclusivity -0.44 -0.60 – -0.28 <0.001
Overall Value 19.45 10.14 – 28.77 <0.001
Overall Value^2 10.94 6.37 – 15.50 <0.001
Relative Value -0.03 -0.06 – 0.00 0.069
Trial Order 0.01 -0.03 – 0.05 0.714
Incl by OV -17.46 -25.30 – -9.62 <0.001
Incl by OV^2 -5.06 -10.08 – -0.04 0.048
Incl by RV -0.01 -0.06 – 0.04 0.822
N participant 82
Observations 10138
Marginal R2 / Conditional R2 0.132 / NA
df.total.valid.12.lvd <- df.total.valid.12 %>% filter(valueDiff<1) %>%
  mutate(scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledTrialNum=scale(trialN))


model.conflict.12.lvd <- lmerTest::lmer(conflict ~ catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.valid.12.lvd)
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 1 negative eigenvalue: -3.5e-05
tab_model(model.conflict.12.lvd,transform = NULL,show.re.var = F,pred.labels = c("Intercept","Inclusivity","Overall Value","Overall Value^2","Relative Value","Trial Order","Incl by OV","Incl by OV^2","Incl by RV"),dv.labels = c("Conflict"))
  Conflict
Predictors Estimates CI p
Intercept 2.54 2.40 – 2.68 <0.001
Inclusivity -0.45 -0.64 – -0.25 <0.001
Overall Value 11.22 5.02 – 17.41 <0.001
Overall Value^2 9.17 5.20 – 13.13 <0.001
Relative Value -0.01 -0.06 – 0.03 0.521
Trial Order -0.01 -0.06 – 0.04 0.619
Incl by OV -7.62 -14.12 – -1.12 0.022
Incl by OV^2 -1.80 -7.37 – 3.76 0.525
Incl by RV 0.10 0.02 – 0.18 0.019
N participant 82
Observations 2638
Marginal R2 / Conditional R2 0.154 / NA
p1 <- ggplot(df.total.rt.12 %>% filter(catChoiceCondition=='XOR'), aes(meanValue,valueDiff)) + geom_point(color='#0673C3',size=0.5) + theme_classic() + xlab('Overall value') + ylab('Relative Value') + theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6),strip.text.y = element_blank())
p1 <- ggExtra::ggMarginal(p1, type = "histogram") 

p2 <- ggplot(df.total.rt.12 %>% filter(catChoiceCondition=='OR'), aes(meanValue,valueDiff)) + geom_point(color='#00B024',size=0.5) + theme_classic() +  xlab('Overall value') + ylab('Relative Value') + theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6),strip.text.y = element_blank())
p2 <- ggExtra::ggMarginal(p2, type = "histogram") 

ggsave(filename = '../Figures/Figure_MVDV1.pdf',p1,units = 'cm',width = 3,height = 3)
ggsave(filename = '../Figures/Figure_MVDV2.pdf',p2,units = 'cm',width = 3,height = 3)
eff_mv.cfl.12 <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.conflict.12.lvd,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.valid.12$scaledMeanValue,0.025),
                                                    quantile(df.total.valid.12$scaledMeanValue,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledValueDiff, scaledTrialNum, scaledMeanValue are one-column
## matrices that were converted to vectors
IA.mv.cfl.12 <- as.data.frame(eff_mv.cfl.12)

IA.mv.cfl.12$catChoiceCondition <- relevel(IA.mv.cfl.12$catChoiceCondition,ref = 'XOR')

p.eff.mv.cfl.12<-ggplot(data=IA.mv.cfl.12, aes(x=scaledMeanValue, y=fit,group=catChoiceCondition)) + 
  geom_line(size=0.5,aes(color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.cfl.12, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab("Conflict") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6),strip.text.y = element_blank()) + 
  scale_fill_manual("",values=c('#0673C3','#00B024','#008012')) + 
  scale_color_manual("",values=c('#0673C3','#00B024','#008012')) + 
  coord_cartesian(ylim=c(1,5)) + scale_y_continuous(breaks = c(1,5))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
ggsave(filename = '../Figures/Figure_LVD.pdf',p.eff.mv.cfl.12,units = 'cm',width = 3,height = 3)
df.volun.summary <- df.total.rt.12 %>% filter(catChoiceCondition=='OR',NChosen >= 1) %>% 
  rowwise() %>% dplyr::mutate(totalRT=getSumRT(c(RT1,RT2,RT3,RT4),
                                        c(Order1,Order2,Order3,Order4))) %>% ungroup() %>%
  group_by(NChosen) %>% summarise(ntrial=n(),
                                  meanSumRT=mean(totalRT))

df.volun.RT.summary.1 <- df.total.rt.12 %>% filter(catChoiceCondition=='OR',firstRT>0) %>% group_by(NChosen) %>%
  summarise(sRT=mean(firstRT)) %>% mutate(selection = 1)

df.volun.RT.summary.2 <- df.total.rt.12 %>% rowwise() %>% mutate(secondRT=getSecond(c(RT1,RT2,RT3,RT4),
                                        c(Order1,Order2,Order3,Order4))) %>% ungroup() %>% filter(catChoiceCondition=='OR',secondRT>0) %>% group_by(NChosen) %>%
  summarise(sRT=mean(secondRT-firstRT)) %>% mutate(selection = 2)

df.volun.RT.summary.3 <- df.total.rt.12 %>% 
  rowwise() %>% dplyr::mutate(secondRT=getSecond(c(RT1,RT2,RT3,RT4),
                                        c(Order1,Order2,Order3,Order4)),thirdRT=getThird(c(RT1,RT2,RT3,RT4),
                                        c(Order1,Order2,Order3,Order4))) %>% ungroup() %>% filter(catChoiceCondition=='OR',thirdRT>0) %>%  group_by(NChosen) %>%
  summarise(sRT=mean(thirdRT-secondRT)) %>% mutate(selection = 3)

df.volun.RT.summary.4 <- df.total.rt.12 %>% 
  rowwise() %>% dplyr::mutate(fourthRT=getFourth(c(RT1,RT2,RT3,RT4),
                                        c(Order1,Order2,Order3,Order4)),
                              thirdRT=getThird(c(RT1,RT2,RT3,RT4),
                                        c(Order1,Order2,Order3,Order4))) %>% ungroup() %>% filter(catChoiceCondition=='OR',fourthRT>0) %>%  group_by(NChosen) %>%
  summarise(sRT=mean(fourthRT-thirdRT)) %>% mutate(selection = 4)

df.volun.RT.summary <- inner_join(rbind(df.volun.RT.summary.1,df.volun.RT.summary.2,
                             df.volun.RT.summary.3,df.volun.RT.summary.4) %>%  pivot_wider(
    names_from = selection,
    values_from = sRT,names_prefix='sRT_'
  ),df.volun.summary,by='NChosen')
coeff.rt <- t(fixef(model.RT.12)['catChoiceConditionOR-XOR'])
df.ci <- confint(model.RT.12,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.rt <- df.ci['catChoiceConditionOR-XOR',]
estimate.rt <- cbind(coeff.rt,t(ci.rt))
colnames(estimate.rt)<-c('coeff','lower','upper')

coeff.acc <- t(fixef(model.acc.12.dummy)['catChoiceConditionOR-XOR'])
df.ci <- confint(model.acc.12.dummy,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.acc <- df.ci['catChoiceConditionOR-XOR',]
estimate.acc <- cbind(coeff.acc,t(ci.acc))
colnames(estimate.acc)<-c('coeff','lower','upper')

coeff.conf <- t(fixef(model.conflict.12)['catChoiceConditionOR-XOR'])
df.ci <- confint(model.conflict.12,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.conf <- df.ci['catChoiceConditionOR-XOR',]
estimate.conf <- cbind(coeff.conf,t(ci.conf))
colnames(estimate.conf)<-c('coeff','lower','upper')

coeff.rr <- t(fixef(model.rr.12)['catChoiceConditionOR-XOR'])
df.ci <- confint(model.rr.12,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.rr <- df.ci['catChoiceConditionOR-XOR',]
estimate.rr <- cbind(coeff.rr,t(ci.rr))
colnames(estimate.rr)<-c('coeff','lower','upper')

estimate.all <- data.frame(rbind(estimate.rt,estimate.acc,estimate.conf,estimate.rr))
estimate.all$var <- c('RT','Acc','Conflict','RR')
p.diff.acc.12 <- ggplot(estimate.all %>% filter(var %in% c('Acc')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Inclusivity")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks =element_line(size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("Acc"='P(Best First)')) + scale_y_continuous(limits = c(-0.1,0.004),breaks = c(-0.1,0))
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
p.diff.acc.12

p.diff.rt.12 <- ggplot(estimate.all %>% filter(var %in% c('RT')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Inclusivity\n(sec)")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks =element_line(size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("RT"='RT')) + scale_y_continuous(limits = c(-0.5,0.02),breaks = c(-0.5,0))

p.diff.rt.12

p.diff.conflict.12 <- ggplot(estimate.all %>% filter(var %in% c('Conflict')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Inclusivity")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks =element_line(size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("Conflict"='Conflict')) + scale_y_continuous(limits = c(-1,.02),breaks = c(-1,0))
p.diff.conflict.12

p.diff.rr.12 <- ggplot(estimate.all %>% filter(var %in% c('RR')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Inclusivity\n(Unit Value/sec)")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none",axis.ticks =element_line(size=0.2)) +
  scale_x_discrete(labels=c("RR"='Reward Rate')) + scale_y_continuous(limits = c(-0.02,0.5),breaks = c(0,0.5))
p.diff.rr.12

4.1.0.1 Get predictions about value effects for selection study (1a and 1b)

eff_mv.RT.12 <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.RT.12,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.rt.12$scaledMeanValue,0.025),
                                                    quantile(df.total.rt.12$scaledMeanValue,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.mv.RT.12 <- as.data.frame(eff_mv.RT.12) %>% dplyr::mutate(study='Study 12')

p.eff.mv.RT.12<-ggplot(data=IA.mv.RT.12, aes(x=scaledMeanValue, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.RT.12, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall Value\n(z-scored)") + ylab("RT (sec)")  + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),legend.justification=c(1,1),legend.position='none',text = element_text(size=6),axis.ticks =element_line(colour='black',size=0.2)) +  
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))
p.eff.mv.RT.12

eff_vd.RT.12 <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.RT.12,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.rt.12$scaledValueDiff,0.025),
                                                    quantile(df.total.rt.12$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.vd.RT.12 <- as.data.frame(eff_vd.RT.12) %>% dplyr::mutate(study='Study 12')

p.eff.vd.RT.12<-ggplot(data=IA.vd.RT.12, aes(x=scaledValueDiff, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.RT.12, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("RT (sec)")  + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),legend.justification=c(1,1),legend.position='none',text = element_text(size=6),axis.ticks =element_line(colour='black',size=0.2)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))
p.eff.vd.RT.12

eff_mv.Acc.12 <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.acc.12,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.rt.12$scaledMeanValue,0.025),
                                                    quantile(df.total.rt.12$scaledMeanValue,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.mv.Acc.12 <- as.data.frame(eff_mv.Acc.12) %>% dplyr::mutate(study='Study 12')

p.eff.mv.Acc.12<-ggplot(data=IA.mv.Acc.12, aes(x=scaledMeanValue, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.Acc.12, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall Value\n(z-scored)") + ylab("P(Best First)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),legend.justification=c(1,1),legend.position='none',text = element_text(size=6),axis.ticks =element_line(colour='black',size=0.2)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(0.1,0.9)) + scale_y_continuous(breaks = c(0.1,0.9))
p.eff.mv.Acc.12

eff_vd.Acc.12 <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.acc.12,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.rt.12$scaledValueDiff,0.025),
                                                    quantile(df.total.rt.12$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.vd.Acc.12 <- as.data.frame(eff_vd.Acc.12) %>% dplyr::mutate(study='Study 12')

p.eff.vd.Acc.12<-ggplot(data=IA.vd.Acc.12, aes(x=scaledValueDiff, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.Acc.12, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("P(Best First)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),legend.justification=c(1,1),legend.position='none',text = element_text(size=6),axis.ticks =element_line(colour='black',size=0.2)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(0.1,0.9)) + scale_y_continuous(breaks = c(0.1,0.9))
p.eff.vd.Acc.12

lay <- rbind(c(1, 4, 4, 4, 7),
             c(2, 2, NA,3, 3),
             c(5, 5, NA,6, 6))

plots <- list(p.diff.rt.12,p.eff.vd.RT.12,p.eff.vd.Acc.12,
              p.diff.acc.12,p.eff.mv.RT.12,p.eff.mv.Acc.12,p.diff.rr.12)
grobs <- list()
widths <- list()
heights <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths
    heights[[i]] <- grobs[[i]]$heights
}

maxwidth <- do.call(grid::unit.pmax, widths)
maxheight <- do.call(grid::unit.pmax,heights)

for (i in c(2,3,5,6)){
     grobs[[i]]$widths <- as.list(maxwidth)
}

for (i in 1:length(grobs)){
     grobs[[i]]$heights <- as.list(maxheight)
}

widths <- list()

for (i in c(1,4,7)){
    widths[[i]] <- grobs[[i]]$widths
}

maxwidth <- do.call(grid::unit.pmax,widths)

for (i in c(1,4,7)){
     grobs[[i]]$widths <- as.list(maxwidth)
}

p<-grid.arrange(grobs = grobs, layout_matrix = lay,widths=unit(c(2,0.9,0.2,0.9,2), c("cm", "cm")),heights=unit(c(3,3,3),c('cm','cm')))

ggsave(filename = '../Figures/Figure2.pdf',p,units = 'cm',width = 10,height = 15)

4.2 Prepare simulation

df.total.rt.values <- df.total.rt.12 %>% dplyr::select(Value1,Value2,Value3,Value4)
write.csv(x = df.total.rt.values,file = '../Model/data/trial/simulation_value_12.csv',row.names = F,col.names = T)
## Warning in write.csv(x = df.total.rt.values, file =
## "../Model/data/trial/simulation_value_12.csv", : attempt to set 'col.names'
## ignored
coeff.mat.RT.12 <- coef(summary(model.RT.12.coeff))
coeff.mat.RT.12.ov <- data.frame(coeff.mat.RT.12[c('catChoiceConditionOR:scaledMeanValue',
                                      'catChoiceConditionXOR:scaledMeanValue'),
                                    c('Estimate','Std. Error')])
coeff.mat.RT.12.ov$catChoiceCondition <- c('OR','XOR')
colnames(coeff.mat.RT.12.ov) <- c('beta_OV','se_OV','catChoiceCondition')
coeff.mat.RT.12.vd <- data.frame(coeff.mat.RT.12[c('catChoiceConditionOR:scaledValueDiff',
                                      'catChoiceConditionXOR:scaledValueDiff')
                                    ,c('Estimate','Std. Error')])
coeff.mat.RT.12.vd$catChoiceCondition <- c('OR','XOR')
colnames(coeff.mat.RT.12.vd) <- c('beta_VD','se_VD','catChoiceCondition')

coeff.mat.RT.12 <- inner_join(data.frame(coeff.mat.RT.12.ov),
                             data.frame(coeff.mat.RT.12.vd),by='catChoiceCondition') %>% mutate(study='Study 12')
rownames(coeff.mat.RT.12) <- NULL

coeff.mat.RT <- rbind(coeff.mat.RT.12)

coeff.mat.Acc.12 <- coef(summary(model.acc.12.coeff))
coeff.mat.Acc.12.ov <- data.frame(coeff.mat.Acc.12[c('catChoiceConditionOR:scaledMeanValue',
                                      'catChoiceConditionXOR:scaledMeanValue'),
                                    c('Estimate','Std. Error')])
coeff.mat.Acc.12.ov$catChoiceCondition <- c('OR','XOR')
colnames(coeff.mat.Acc.12.ov) <- c('beta_OV','se_OV','catChoiceCondition')
coeff.mat.Acc.12.vd <- data.frame(coeff.mat.Acc.12[c('catChoiceConditionOR:scaledValueDiff',
                                      'catChoiceConditionXOR:scaledValueDiff')
                                    ,c('Estimate','Std. Error')])
coeff.mat.Acc.12.vd$catChoiceCondition <- c('OR','XOR')
colnames(coeff.mat.Acc.12.vd) <- c('beta_VD','se_VD','catChoiceCondition')

coeff.mat.Acc.12 <- inner_join(data.frame(coeff.mat.Acc.12.ov),
                             data.frame(coeff.mat.Acc.12.vd),by='catChoiceCondition') %>% mutate(study='Study 12')
rownames(coeff.mat.Acc.12) <- NULL

coeff.mat.Acc <- rbind(coeff.mat.Acc.12)

#coeff.mat.RT$catChoiceCondition <- rownames(coeff.mat.RT)
eff_cc.acc.12 <- Effect(c("catChoiceCondition"),model.acc.12.coeff)
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.cc.acc.12 <- as.data.frame(eff_cc.acc.12) %>% dplyr::mutate(study='Study 12')

IA.cc.acc <- rbind(IA.cc.acc.12) %>% 
  dplyr::mutate(catChoiceCondition=factor(catChoiceCondition,levels=c('XOR','OR')))

eff_cc.RT.12 <- Effect(c("catChoiceCondition"),model.RT.12.coeff)
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.cc.RT.12 <- as.data.frame(eff_cc.RT.12) %>% dplyr::mutate(study='Study 12')

IA.cc.RT <- rbind(IA.cc.RT.12) %>% 
  dplyr::mutate(catChoiceCondition=factor(catChoiceCondition,levels=c('XOR','OR')))
IA.cc.acc.rt <- inner_join(IA.cc.acc %>% dplyr::select(catChoiceCondition,fit,se,study) %>%
                             rename(I_acc=fit,se_acc=se),
                           IA.cc.RT %>% dplyr::select(catChoiceCondition,fit,se,study) %>%
                             rename(I_rt=fit,se_rt=se),by=c('catChoiceCondition','study'))
write.csv(coeff.mat.Acc,'../Model/data/outcome/coeff_acc_12.csv',row.names = F,col.names = T)
## Warning in write.csv(coeff.mat.Acc, "../Model/data/outcome/coeff_acc_12.csv", :
## attempt to set 'col.names' ignored
write.csv(coeff.mat.RT,'../Model/data/outcome/coeff_rt_12.csv',row.names = F,col.names = T)
## Warning in write.csv(coeff.mat.RT, "../Model/data/outcome/coeff_rt_12.csv", :
## attempt to set 'col.names' ignored
write.csv(IA.cc.acc.rt,'../Model/data/outcome/intercept_acc_rt_12.csv',row.names = F,col.names = T)
## Warning in write.csv(IA.cc.acc.rt,
## "../Model/data/outcome/intercept_acc_rt_12.csv", : attempt to set 'col.names'
## ignored

4.2.1 LCA stuff goes here

coeff.mat.Acc <- read.csv('../Model/data/outcome/coeff_acc_12.csv')
coeff.mat.RT <- read.csv('../Model/data/outcome/coeff_rt_12.csv')
IA.cc.acc.rt <- read.csv('../Model/data/outcome/intercept_acc_rt_12.csv')
prediction12_full <- read.csv('../Model/gridsearch/result/prediction_task_12_full.csv') %>% 
  mutate(catChoiceCondition=relevel(factor(condition),'XOR'))
prediction12_inhi <- read.csv('../Model/gridsearch/result/prediction_task_12_inhib.csv') %>% 
  mutate(catChoiceCondition=relevel(factor(condition),'XOR'))
prediction12_thre <- read.csv('../Model/gridsearch/result/prediction_task_12_thresh.csv') %>% 
  mutate(catChoiceCondition=relevel(factor(condition),'XOR'))
prediction12_end <- read.csv('../Model/gridsearch/result/prediction_task_12_ddl.csv') %>% 
  mutate(catChoiceCondition=relevel(factor(condition),'XOR'))
prediction12_bound <- read.csv('../Model/gridsearch/result/prediction_task_12_bound.csv') %>% 
  mutate(catChoiceCondition=relevel(factor(condition),'XOR'))
df.inhib <- read.csv('../Model/gridsearch/result/trend_m.csv')
df.thres <- read.csv('../Model/gridsearch/result/trend_a.csv')
df.end <- read.csv('../Model/gridsearch/result/trend_theta.csv')
p1 <- ggplot() + 
  geom_path(data = df.thres,aes(x=b1_RT,y=b2_RT),color='#587F13',alpha=0.5) + 
  geom_point(data = df.thres,aes(x=b1_RT,y=b2_RT),color='#587F13',size=0.5,alpha=0.5) + 
  geom_path(data = df.end,aes(x=b1_RT,y=b2_RT),color='#5E1796',alpha=0.5) + 
  geom_point(data = df.end,aes(x=b1_RT,y=b2_RT),color='#5E1796',size=0.5,alpha=0.5) + 
  
  geom_path(data = df.inhib,aes(x=b1_RT,y=b2_RT),color='red') + 
  geom_point(data = df.inhib,aes(x=b1_RT,y=b2_RT),color='red',size=0.5) + xlab('OV Effect on RT') + ylab('RV Effect on RT') +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.background = element_blank(), axis.line = element_line(colour = "black",size=0.2),text = element_text(size=6),axis.ticks = element_line(color='black',size=0.2)) + 
  scale_y_continuous(labels=function(x) sprintf("%.1f", x),limits = c(-0.4,-0),breaks = c(-0.4,-0))  + 
  scale_x_continuous(labels=function(x) sprintf("%.1f", x),limits = c(-0.5,-0.1),breaks = c(-0.5,-0.1))


p1
## Warning: Removed 3 rows containing missing values or values outside the scale range
## (`geom_path()`).
## Warning: Removed 3 rows containing missing values or values outside the scale range
## (`geom_point()`).
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_path()`).
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

p2<-ggplot() + geom_vline(xintercept = 0,linetype="dashed",size=0.5) +
  geom_path(data = df.thres,aes(x=b1_Acc,y=b2_Acc),color='#587F13',alpha=0.5) + 
  geom_point(data = df.thres,aes(x=b1_Acc,y=b2_Acc),color='#587F13',size=0.5,alpha=0.5) + 
  geom_path(data = df.end,aes(x=b1_Acc,y=b2_Acc),color='#5E1796',alpha=0.5) + 
  geom_point(data = df.end,aes(x=b1_Acc,y=b2_Acc),color='#5E1796',size=0.5,alpha=0.5) + 
  
  geom_path(data = df.inhib,aes(x=b1_Acc,y=b2_Acc),color='red') + 
  geom_point(data = df.inhib,aes(x=b1_Acc,y=b2_Acc),color='red',size=0.5) + xlab('OV Effect on Accuracy') + ylab('RV Effect on Accuracy') +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.background = element_blank(), axis.line = element_line(colour = "black",size=0.2),text = element_text(size=6),axis.ticks = element_line(color='black',size=0.2)) + 
  scale_y_continuous(labels=function(x) sprintf("%.1f", x),limits = c(.4,.8),breaks = c(.4,.8))  + 
  scale_x_continuous(labels=function(x) sprintf("%.1f", x),limits = c(-0.1,.1),breaks = c(-0.1,.1))
p2

p3<-ggplot() + 
  geom_path(data = df.thres,aes(x=I_RT,y=I_Acc),color='#587F13',alpha=0.5) + 
  geom_point(data = df.thres,aes(x=I_RT,y=I_Acc),color='#587F13',size=0.5,alpha=0.5) + 
  geom_path(data = df.end,aes(x=I_RT,y=I_Acc),color='#5E1796',alpha=0.5) + 
  geom_point(data = df.end,aes(x=I_RT,y=I_Acc),color='#5E1796',size=0.5,alpha=0.5) + 
    geom_path(data = df.inhib,aes(x=I_RT,y=I_Acc),color='red') + 
  geom_point(data = df.inhib,aes(x=I_RT,y=I_Acc),color='red',size=0.5) +ylab('Intercept of Accuracy') + xlab('Intercept of RT')+
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.background = element_blank(), axis.line = element_line(colour = "black",size=0.2),text = element_text(size=6),axis.ticks = element_line(color='black',size=0.2)) + 
  scale_y_continuous(labels=function(x) sprintf("%.1f", x),limits = c(.35,.55),breaks = c(.4,.5))  + 
  scale_x_continuous(labels=function(x) sprintf("%.1f", x),limits = c(0,5),breaks = c(0,5))

p3

IA.cc.acc.rt$catChoiceCondition<-relevel(factor(IA.cc.acc.rt$catChoiceCondition),'XOR')


p.pred.real.int<-ggplot(data=IA.cc.acc.rt,aes(x=I_rt,y=I_acc,color=catChoiceCondition)) + geom_line(data=df.inhib,aes(x=I_RT,y=I_Acc),color='red',alpha=0.5,linetype=2,linewidth=0.5) + geom_point(size=1) +
  geom_errorbar(aes(ymin = I_acc-1.96*se_acc, ymax = I_acc+1.96*se_acc),width=.05) +
  geom_errorbarh(aes(xmin = I_rt-1.96*se_rt, xmax = I_rt+1.96*se_rt),height=.005) + xlab('Intercept of RT') + ylab('Intercept of Accuracy') +
  geom_line(data=prediction12_inhi,aes(x=I_RT,y=I_Acc),color='black',linewidth=0.5) +
   geom_point(data=prediction12_inhi,aes(x=I_RT,y=I_Acc,fill=catChoiceCondition),shape=24,size=1,color='black') + theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) + scale_fill_manual(values=c('#0673C3','#00B024')) +  scale_color_manual(values=c('#0673C3','#00B024')) + scale_x_continuous(limits = c(2.2,3.2),breaks=c(2.2,3.2)) + scale_y_continuous(limits=c(0.4,0.55),breaks=c(0.4,0.55))
p.pred.real.int
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_line()`).

# ggsave('figures/int_prediction_data_new_12.pdf',width = 12, height = 6, units = "cm")
coeff.mat.RT$catChoiceCondition<-relevel(factor(coeff.mat.RT$catChoiceCondition),'XOR')

df.coeff.mat.RT <- data.frame(coeff.mat.RT)

p.pred.real.RT<-ggplot(data=df.coeff.mat.RT,aes(x=beta_OV,y=beta_VD,color=catChoiceCondition)) +
  geom_line(data=df.inhib,aes(x=b1_RT,y=b2_RT),color='red',alpha=0.5,linetype=2,linewidth=0.5) + geom_point(size=1) +
  geom_errorbar(aes(ymin = beta_VD-1.96*se_VD, ymax = beta_VD+1.96*se_VD),width=.01) +
  geom_errorbarh(aes(xmin = beta_OV-1.96*se_OV, xmax = beta_OV+1.96*se_OV),height=.01) + xlab('OV Effect on RT') + ylab('RV Effect on RT') +  geom_line(data=prediction12_inhi,aes(x=b1_RT,y=b2_RT),color='black',linewidth=0.5) +geom_point(data=prediction12_inhi,aes(x=b1_RT,y=b2_RT,fill=catChoiceCondition),shape=24,size=1,color='black') +
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) + scale_fill_manual(values=c('#0673C3','#00B024')) +
  scale_fill_manual(values=c('#0673C3','#00B024')) + scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(-0.3,-.0),breaks=c(-.3,-.0)) + scale_x_continuous(limits=c(-.5,-0.2),breaks=c(-0.5,-0.2))
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.
p.pred.real.RT
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_line()`).

# ggsave('figures/RT_prediction_data_new_12.pdf',width = 16, height = 6, units = "cm")
coeff.mat.Acc$catChoiceCondition<-relevel(factor(coeff.mat.Acc$catChoiceCondition),'XOR')


p.pred.real.acc<-ggplot(data=data.frame(coeff.mat.Acc),aes(x=beta_OV,y=beta_VD,color=catChoiceCondition)) +
  geom_line(data=df.inhib,aes(x=b1_Acc,y=b2_Acc),color='red',alpha=0.5,linetype=2,linewidth=0.5) +geom_point(size=1) +
  geom_errorbar(aes(ymin = beta_VD-se_VD*1.96, ymax = beta_VD+se_VD*1.96),width=.01) +
  geom_errorbarh(aes(xmin = beta_OV-se_OV*1.96, xmax = beta_OV+se_OV*1.96),height=.01) + xlab('OV Effect on Accuracy') + ylab('RV Effect on Accuracy') + geom_line(data=prediction12_inhi,aes(x=b1_Acc,y=b2_Acc),color='black',linewidth=0.5) +
  geom_point(data=prediction12_inhi,aes(x=b1_Acc,y=b2_Acc,fill=catChoiceCondition),shape=24,size=1,color='black') + 
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) + scale_fill_manual(values=c('#0673C3','#00B024')) + scale_fill_manual(values=c('#0673C3','#00B024')) +  scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(.4,.8),breaks=c(.4,.8)) +
  scale_x_continuous(limits=c(-.15,.15),breaks=c(-0.15,.15))
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.
p.pred.real.acc

# ggsave('figures/Acc_prediction_data_new_12.pdf',width = 8, height = 6, units = "cm")
lay <- rbind(c(1,NA,2,NA,3),c(NA,NA,NA),c(4,NA,5,NA,6))
## Warning in rbind(c(1, NA, 2, NA, 3), c(NA, NA, NA), c(4, NA, 5, NA, 6)): number
## of columns of result is not a multiple of vector length (arg 2)
plots <- list(p3,p1,p2,p.pred.real.int,p.pred.real.RT,p.pred.real.acc)
grobs <- list()
widths <- list()
heights <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths
    heights[[i]] <- grobs[[i]]$heights
}
## Warning: Removed 3 rows containing missing values or values outside the scale range
## (`geom_path()`).
## Warning: Removed 3 rows containing missing values or values outside the scale range
## (`geom_point()`).
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_path()`).
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_line()`).
## Removed 1 row containing missing values or values outside the scale range
## (`geom_line()`).
maxwidth <- do.call(grid::unit.pmax, widths)
maxheight <- do.call(grid::unit.pmax,heights)

for (i in 1:length(grobs)){
     grobs[[i]]$heights <- as.list(maxheight)
     grobs[[i]]$widths <- as.list(maxwidth)
}

p<-grid.arrange(grobs = grobs, layout_matrix = lay,widths=unit(c(3,0.5,3,0.5,3), c("cm", "cm")),heights=unit(c(3,0.25,3),c('cm','cm')))

ggsave(filename = '../Figures//Figure3_CD.pdf',p,units = 'cm',width = 28,height = 10)
p.pred.real.int.inhi<-ggplot(data=IA.cc.acc.rt,aes(x=I_rt,y=I_acc,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = I_acc-1.96*se_acc, ymax = I_acc+1.96*se_acc),width=.05) +
  geom_errorbarh(aes(xmin = I_rt-1.96*se_rt, xmax = I_rt+1.96*se_rt),height=.005) + xlab('Intercept of RT') + ylab('Intercept of Accuracy') +
  geom_line(data=prediction12_inhi,aes(x=I_RT,y=I_Acc),color='black',linewidth=0.5) +
   geom_point(data=prediction12_inhi,aes(x=I_RT,y=I_Acc,fill=catChoiceCondition),shape=24,size=1,color='black') + theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) + scale_fill_manual(values=c('#0673C3','#00B024')) +  scale_color_manual(values=c('#0673C3','#00B024')) + scale_x_continuous(limits = c(2.2,3.2),breaks=c(2.2,3.2)) + scale_y_continuous(limits=c(0.4,0.55),breaks=c(0.4,0.55))
p.pred.real.int.inhi

p.pred.real.RT.inhi<-ggplot(data=df.coeff.mat.RT,aes(x=beta_OV,y=beta_VD,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = beta_VD-1.96*se_VD, ymax = beta_VD+1.96*se_VD),width=.01) +
  geom_errorbarh(aes(xmin = beta_OV-1.96*se_OV, xmax = beta_OV+1.96*se_OV),height=.01) + xlab('OV Effect on RT') + ylab('RV Effect on RT') +  geom_line(data=prediction12_inhi,aes(x=b1_RT,y=b2_RT),color='black',linewidth=0.5) +geom_point(data=prediction12_inhi,aes(x=b1_RT,y=b2_RT,fill=catChoiceCondition),shape=24,size=1,color='black') +
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) +
  scale_fill_manual(values=c('#0673C3','#00B024')) + scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(-0.3,-.1),breaks=c(-.3,-.1)) + scale_x_continuous(limits=c(-.5,-0.2),breaks=c(-0.5,-0.2))
p.pred.real.RT.inhi

p.pred.real.acc.inhi<-ggplot(data=data.frame(coeff.mat.Acc),aes(x=beta_OV,y=beta_VD,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = beta_VD-se_VD*1.96, ymax = beta_VD+se_VD*1.96),width=.01) +
  geom_errorbarh(aes(xmin = beta_OV-se_OV*1.96, xmax = beta_OV+se_OV*1.96),height=.01) + xlab('OV Effect on Accuracy') + ylab('RV Effect on Accuracy') + geom_line(data=prediction12_inhi,aes(x=b1_Acc,y=b2_Acc),color='black',linewidth=0.5) +
  geom_point(data=prediction12_inhi,aes(x=b1_Acc,y=b2_Acc,fill=catChoiceCondition),shape=24,size=1,color='black') + 
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) +scale_fill_manual(values=c('#0673C3','#00B024')) +  scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(.4,.8),breaks=c(.4,.8)) +
  scale_x_continuous(limits=c(-.15,.15),breaks=c(-0.15,.15))
p.pred.real.acc.inhi

# ggsave('figures/int_prediction_data_new_12.pdf',width = 12, height = 6, units = "cm")
p.pred.real.int.full<-ggplot(data=IA.cc.acc.rt,aes(x=I_rt,y=I_acc,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = I_acc-1.96*se_acc, ymax = I_acc+1.96*se_acc),width=.05) +
  geom_errorbarh(aes(xmin = I_rt-1.96*se_rt, xmax = I_rt+1.96*se_rt),height=.005) + xlab('Intercept of RT') + ylab('Intercept of Accuracy') +
  geom_line(data=prediction12_full,aes(x=I_RT,y=I_Acc),color='black',linewidth=0.5) +
   geom_point(data=prediction12_full,aes(x=I_RT,y=I_Acc,fill=catChoiceCondition),shape=24,size=1,color='black') + theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) + scale_fill_manual(values=c('#0673C3','#00B024')) +  scale_color_manual(values=c('#0673C3','#00B024')) + scale_x_continuous(limits = c(2.2,3.2),breaks=c(2.2,3.2)) + scale_y_continuous(limits=c(0.4,0.55),breaks=c(0.4,0.55))
p.pred.real.int.full

p.pred.real.RT.full<-ggplot(data=df.coeff.mat.RT,aes(x=beta_OV,y=beta_VD,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = beta_VD-1.96*se_VD, ymax = beta_VD+1.96*se_VD),width=.01) +
  geom_errorbarh(aes(xmin = beta_OV-1.96*se_OV, xmax = beta_OV+1.96*se_OV),height=.01) + xlab('OV Effect on RT') + ylab('RV Effect on RT') +  geom_line(data=prediction12_full,aes(x=b1_RT,y=b2_RT),color='black',linewidth=0.5) +geom_point(data=prediction12_full,aes(x=b1_RT,y=b2_RT,fill=catChoiceCondition),shape=24,size=1,color='black') +
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) +
  scale_fill_manual(values=c('#0673C3','#00B024')) + scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(-0.3,-.1),breaks=c(-.3,-.1)) + scale_x_continuous(limits=c(-.5,-0.2),breaks=c(-0.5,-0.2))
p.pred.real.RT.full

p.pred.real.acc.full<-ggplot(data=data.frame(coeff.mat.Acc),aes(x=beta_OV,y=beta_VD,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = beta_VD-se_VD*1.96, ymax = beta_VD+se_VD*1.96),width=.01) +
  geom_errorbarh(aes(xmin = beta_OV-se_OV*1.96, xmax = beta_OV+se_OV*1.96),height=.01) + xlab('OV Effect on Accuracy') + ylab('RV Effect on Accuracy') + geom_line(data=prediction12_full,aes(x=b1_Acc,y=b2_Acc),color='black',linewidth=0.5) +
  geom_point(data=prediction12_full,aes(x=b1_Acc,y=b2_Acc,fill=catChoiceCondition),shape=24,size=1,color='black') + 
  theme_bw()+ theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) + scale_fill_manual(values=c('#0673C3','#00B024')) +  scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(.4,.8),breaks=c(.4,.8)) +
  scale_x_continuous(limits=c(-.15,.15),breaks=c(-0.15,.15))
p.pred.real.acc.full

# ggsave('figures/int_prediction_data_new_12.pdf',width = 12, height = 6, units = "cm")
p.pred.real.int.thre<-ggplot(data=IA.cc.acc.rt,aes(x=I_rt,y=I_acc,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = I_acc-1.96*se_acc, ymax = I_acc+1.96*se_acc),width=.05) +
  geom_errorbarh(aes(xmin = I_rt-1.96*se_rt, xmax = I_rt+1.96*se_rt),height=.005) + xlab('Intercept of RT') + ylab('Intercept of Accuracy') +
  geom_line(data=prediction12_thre,aes(x=I_RT,y=I_Acc),color='black',linewidth=0.5) +
   geom_point(data=prediction12_thre,aes(x=I_RT,y=I_Acc,fill=catChoiceCondition),shape=24,size=1,color='black') + theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) + scale_fill_manual(values=c('#0673C3','#00B024')) +  scale_color_manual(values=c('#0673C3','#00B024')) + scale_x_continuous(limits = c(2.2,3.2),breaks=c(2.2,3.2)) + scale_y_continuous(limits=c(0.4,0.55),breaks=c(0.4,0.55))
p.pred.real.int.thre

p.pred.real.RT.thre<-ggplot(data=df.coeff.mat.RT,aes(x=beta_OV,y=beta_VD,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = beta_VD-1.96*se_VD, ymax = beta_VD+1.96*se_VD),width=.01) +
  geom_errorbarh(aes(xmin = beta_OV-1.96*se_OV, xmax = beta_OV+1.96*se_OV),height=.01) + xlab('OV Effect on RT') + ylab('RV Effect on RT') +  geom_line(data=prediction12_thre,aes(x=b1_RT,y=b2_RT),color='black',linewidth=0.5) +geom_point(data=prediction12_thre,aes(x=b1_RT,y=b2_RT,fill=catChoiceCondition),shape=24,size=1,color='black') +
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) +
  scale_fill_manual(values=c('#0673C3','#00B024')) + scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(-0.3,-.0),breaks=c(-.3,-.0)) + scale_x_continuous(limits=c(-.5,-0.2),breaks=c(-0.5,-0.2))
p.pred.real.RT.thre

p.pred.real.acc.thre<-ggplot(data=data.frame(coeff.mat.Acc),aes(x=beta_OV,y=beta_VD,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = beta_VD-se_VD*1.96, ymax = beta_VD+se_VD*1.96),width=.01) +
  geom_errorbarh(aes(xmin = beta_OV-se_OV*1.96, xmax = beta_OV+se_OV*1.96),height=.01) + xlab('OV Effect on Accuracy') + ylab('RV Effect on Accuracy') + geom_line(data=prediction12_thre,aes(x=b1_Acc,y=b2_Acc),color='black',linewidth=0.5) +
  geom_point(data=prediction12_thre,aes(x=b1_Acc,y=b2_Acc,fill=catChoiceCondition),shape=24,size=1,color='black') + 
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) + scale_fill_manual(values=c('#0673C3','#00B024')) +  scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(.4,.8),breaks=c(.4,.8)) +
  scale_x_continuous(limits=c(-.15,.15),breaks=c(-0.15,.15))
p.pred.real.acc.thre

# ggsave('figures/int_prediction_data_new_12.pdf',width = 12, height = 6, units = "cm")
p.pred.real.int.end<-ggplot(data=IA.cc.acc.rt,aes(x=I_rt,y=I_acc,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = I_acc-1.96*se_acc, ymax = I_acc+1.96*se_acc),width=.05) +
  geom_errorbarh(aes(xmin = I_rt-1.96*se_rt, xmax = I_rt+1.96*se_rt),height=.005) + xlab('Intercept of RT') + ylab('Intercept of Accuracy') +
  geom_line(data=prediction12_end,aes(x=I_RT,y=I_Acc),color='black',linewidth=0.5) +
   geom_point(data=prediction12_end,aes(x=I_RT,y=I_Acc,fill=catChoiceCondition),shape=24,size=1,color='black') + theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) + scale_fill_manual(values=c('#0673C3','#00B024')) +  scale_color_manual(values=c('#0673C3','#00B024')) + scale_x_continuous(limits = c(2.2,3.2),breaks=c(2.2,3.2)) + scale_y_continuous(limits=c(0.4,0.55),breaks=c(0.4,0.55))
p.pred.real.int.end

p.pred.real.RT.end<-ggplot(data=df.coeff.mat.RT,aes(x=beta_OV,y=beta_VD,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = beta_VD-1.96*se_VD, ymax = beta_VD+1.96*se_VD),width=.01) +
  geom_errorbarh(aes(xmin = beta_OV-1.96*se_OV, xmax = beta_OV+1.96*se_OV),height=.01) + xlab('OV Effect on RT') + ylab('RV Effect on RT') +  geom_line(data=prediction12_end,aes(x=b1_RT,y=b2_RT),color='black',linewidth=0.5) +geom_point(data=prediction12_end,aes(x=b1_RT,y=b2_RT,fill=catChoiceCondition),shape=24,size=1,color='black') +
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) +
  scale_fill_manual(values=c('#0673C3','#00B024')) + scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(-0.3,-.0),breaks=c(-.3,-.0)) + scale_x_continuous(limits=c(-.5,-0.2),breaks=c(-0.5,-0.2))
p.pred.real.RT.end

p.pred.real.acc.end<-ggplot(data=data.frame(coeff.mat.Acc),aes(x=beta_OV,y=beta_VD,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = beta_VD-se_VD*1.96, ymax = beta_VD+se_VD*1.96),width=.01) +
  geom_errorbarh(aes(xmin = beta_OV-se_OV*1.96, xmax = beta_OV+se_OV*1.96),height=.01) + xlab('OV Effect on Accuracy') + ylab('RV Effect on Accuracy') + geom_line(data=prediction12_end,aes(x=b1_Acc,y=b2_Acc),color='black',linewidth=0.5) +
  geom_point(data=prediction12_end,aes(x=b1_Acc,y=b2_Acc,fill=catChoiceCondition),shape=24,size=1,color='black') + 
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) + scale_fill_manual(values=c('#0673C3','#00B024')) +  scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(.4,.8),breaks=c(.4,.8)) +
  scale_x_continuous(limits=c(-.15,.15),breaks=c(-0.15,.15))
p.pred.real.acc.end

# ggsave('figures/int_prediction_data_new_12.pdf',width = 12, height = 6, units = "cm")
p.pred.real.int.bound<-ggplot(data=IA.cc.acc.rt,aes(x=I_rt,y=I_acc,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = I_acc-1.96*se_acc, ymax = I_acc+1.96*se_acc),width=.05) +
  geom_errorbarh(aes(xmin = I_rt-1.96*se_rt, xmax = I_rt+1.96*se_rt),height=.005) + xlab('Intercept of RT') + ylab('Intercept of Accuracy') +
  geom_line(data=prediction12_bound,aes(x=I_RT,y=I_Acc),color='black',linewidth=0.5) +
   geom_point(data=prediction12_bound,aes(x=I_RT,y=I_Acc,fill=catChoiceCondition),shape=24,size=1,color='black') + theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) + scale_fill_manual(values=c('#0673C3','#00B024')) +  scale_color_manual(values=c('#0673C3','#00B024')) + scale_x_continuous(limits = c(2.2,3.2),breaks=c(2.2,3.2)) + scale_y_continuous(limits=c(0.4,0.55),breaks=c(0.4,0.55))
p.pred.real.int.bound

p.pred.real.RT.bound<-ggplot(data=df.coeff.mat.RT,aes(x=beta_OV,y=beta_VD,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = beta_VD-1.96*se_VD, ymax = beta_VD+1.96*se_VD),width=.01) +
  geom_errorbarh(aes(xmin = beta_OV-1.96*se_OV, xmax = beta_OV+1.96*se_OV),height=.01) + xlab('OV Effect on RT') + ylab('RV Effect on RT') +  geom_line(data=prediction12_bound,aes(x=b1_RT+0.023,y=b2_RT-0.017),color='black',linewidth=0.5) +geom_point(data=prediction12_bound,aes(x=b1_RT+0.023,y=b2_RT-0.017,fill=catChoiceCondition),shape=24,size=1,color='black') +
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) +
  scale_fill_manual(values=c('#0673C3','#00B024')) + scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(-0.3,-.1),breaks=c(-.3,-.1)) + scale_x_continuous(limits=c(-.5,-0.2),breaks=c(-0.5,-0.2))
p.pred.real.RT.bound

p.pred.real.acc.bound<-ggplot(data=data.frame(coeff.mat.Acc),aes(x=beta_OV,y=beta_VD,color=catChoiceCondition)) + geom_point(size=1) +
  geom_errorbar(aes(ymin = beta_VD-se_VD*1.96, ymax = beta_VD+se_VD*1.96),width=.01) +
  geom_errorbarh(aes(xmin = beta_OV-se_OV*1.96, xmax = beta_OV+se_OV*1.96),height=.01) + xlab('OV Effect on Accuracy') + ylab('RV Effect on Accuracy') + geom_line(data=prediction12_bound,aes(x=b1_Acc,y=b2_Acc),color='black',linewidth=0.5) +
  geom_point(data=prediction12_bound,aes(x=b1_Acc,y=b2_Acc,fill=catChoiceCondition),shape=24,size=1,color='black') + 
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2),legend.position = 'none',text = element_text(size=6)) + scale_fill_manual(values=c('#0673C3','#00B024')) +  scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(.4,.8),breaks=c(.4,.8)) +
  scale_x_continuous(limits=c(-.15,.15),breaks=c(-0.15,.15))
p.pred.real.acc.bound

# ggsave('figures/int_prediction_data_new_12.pdf',width = 12, height = 6, units = "cm")
lay <- rbind(c(1,NA,2,NA,3),c(4,NA,5,NA,6),c(7,NA,8,NA,9),c(10,NA,11,NA,12),c(13,NA,14,NA,15))

plots <- list(p.pred.real.int.end,p.pred.real.RT.end,p.pred.real.acc.end,
              p.pred.real.int.thre,p.pred.real.RT.thre,p.pred.real.acc.thre,
              p.pred.real.int.bound,p.pred.real.RT.bound,p.pred.real.acc.bound,
              p.pred.real.int.inhi,p.pred.real.RT.inhi,p.pred.real.acc.inhi,
              p.pred.real.int.full,p.pred.real.RT.full,p.pred.real.acc.full)
grobs <- list()
widths <- list()
heights <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths
    heights[[i]] <- grobs[[i]]$heights
}

maxwidth <- do.call(grid::unit.pmax, widths)
maxheight <- do.call(grid::unit.pmax,heights)

for (i in 1:length(grobs)){
     grobs[[i]]$heights <- as.list(maxheight)
     grobs[[i]]$widths <- as.list(maxwidth)
}

p<-grid.arrange(grobs = grobs, layout_matrix = lay,widths=unit(c(3,1,3,1,3), c("cm", "cm")),heights=unit(c(3,3,3,3,3),c('cm','cm')))

ggsave(filename = '../Figures/Figure_S0.pdf',p,units = 'cm',width = 17,height = 26)

4.3 Conflict

eff_mv.cfl.12 <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.conflict.12,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.valid.12$scaledMeanValue,0.025),
                                                    quantile(df.total.valid.12$scaledMeanValue,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledValueDiff, scaledTrialNum, scaledMeanValue are one-column
## matrices that were converted to vectors
IA.mv.cfl.12 <- as.data.frame(eff_mv.cfl.12)

IA.mv.cfl.12$catChoiceCondition <- relevel(IA.mv.cfl.12$catChoiceCondition,ref = 'XOR')

p.eff.mv.cfl.12<-ggplot(data=IA.mv.cfl.12, aes(x=scaledMeanValue, y=fit,group=catChoiceCondition)) + 
  geom_line(size=0.5,aes(color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.cfl.12, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall Value\n(z-scored)") + ylab("Conflict") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6),strip.text.y = element_blank()) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))

p.eff.mv.cfl.12

marginalConflictMVEffect <- function(model,x,newx) {
  poly.base <- poly(x,2)
  
  new_poly <- predict(poly.base,newx)
  
  coeffs.mv.1 <- summary(model)$coeff[,'Estimate']
  
  eff <- coeffs.mv.1['catChoiceConditionOR-XOR'] + 
    coeffs.mv.1['catChoiceConditionOR-XOR:poly(scaledMeanValue, 2)1']*new_poly[,1] + 
    coeffs.mv.1['catChoiceConditionOR-XOR:poly(scaledMeanValue, 2)2']*new_poly[,2]
  
  cov.mat <- vcov(model)
  
  eff.ci <-  1.96 * sqrt(cov.mat[2,2] + new_poly[,1]^2 * cov.mat[7,7] + new_poly[,2]^2 * cov.mat[8,8] + 
                                 2 * new_poly[,1] * cov.mat[2,7] + 2 * new_poly[,2] * cov.mat[2,8] + 
                                 2 * new_poly[,1] * new_poly[,2] * cov.mat[7,8])
  
  eff.df<-data.frame(x=newx,eff=eff,ci=eff.ci)
  
  return(eff.df)
}
new.mv.1 <- seq(quantile(df.total.valid.12$scaledMeanValue,0.025),
                quantile(df.total.valid.12$scaledMeanValue,0.975),0.1)

eff.df.mv.12 <- marginalConflictMVEffect(model.conflict.12,
                                         df.total.valid.12$scaledMeanValue,
                                         new.mv.1) %>%
  dplyr::mutate(scaledMeanValue=x,
                catChoiceCondition='XOR - OR',
                fit=eff,
                upper=eff+ci,
                lower=eff-ci,
                se=NA,
                study='Study 12')

p.eff.cc.int.12<-ggplot(data=eff.df.mv.12, aes(x=x, y=fit)) + 
  geom_line(size=0.5)+theme_bw(12) +
  geom_ribbon(data=eff.df.mv.12, aes(x=x, max = upper, min = lower),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall Value\n(z-scored)") + ylab('Effect of Inclusivity') +
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks=element_line(color='black',size=0.2),strip.text.y = element_blank()) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  scale_fill_manual("",values=c("#005555","#550055")) + scale_color_manual("",values=c("#005555","#550055")) + # ggtitle('Exclusive - Non-Exclusive') +
  coord_cartesian(ylim=c(-1.6,0.1)) + scale_y_continuous(breaks = c(-1.6,0))

p.eff.cc.int.12

# ggsave('figures/ov_conflict_123.pdf',unit='cm',width=5,height=5)
eff_vd.cfl.12 <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.conflict.12,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.rt.12$scaledValueDiff,0.025),
                                                    quantile(df.total.rt.12$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledValueDiff, scaledTrialNum, scaledMeanValue are one-column
## matrices that were converted to vectors
IA.vd.cfl <- as.data.frame(eff_vd.cfl.12) %>% dplyr::mutate(study='Study 12')


IA.vd.cfl$catChoiceCondition <- relevel(IA.vd.cfl$catChoiceCondition,ref = 'XOR')

p.eff.vd.cfl.12<-ggplot(data=IA.vd.cfl, aes(x=scaledValueDiff, y=fit,group=catChoiceCondition)) +
  geom_line(size=0.5,aes(color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.cfl, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("Conflict") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour='black',size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))

p.eff.vd.cfl.12

#ggsave('Study12_RT.pdf')
lay <- rbind(c(1,NA,2,NA,3,NA,4))

plots <- list(p.diff.conflict.12,p.eff.mv.cfl.12,p.eff.cc.int.12,p.eff.vd.cfl.12)
grobs <- list()
widths <- list()
heights <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths
    heights[[i]] <- grobs[[i]]$heights
}

maxwidth <- do.call(grid::unit.pmax, widths)
maxheight <- do.call(grid::unit.pmax, heights)

for (i in 1:length(grobs)){
  grobs[[i]]$widths <- as.list(maxwidth)
  grobs[[i]]$heights <- as.list(maxheight)
}

for (i in 2:length(grobs)){
  grobs[[i]]$heights <- as.list(maxheight)
} 

p<-grid.arrange(grobs = grobs, layout_matrix = lay,widths=unit(c(2,0.1,2.7,0.1,2.7,0.1,2.7), c("cm", "cm")),heights=unit(c(3),c('cm','cm')))

ggsave(filename = '../Figures/Figure_4.pdf',p,units = 'cm',width = 25,height = 12)
model.RT.3 <- lmerTest::lmer(firstRT ~ catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum + 
                     (1 + catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),
                     data=df.total.rt.3,
                   control=lmerControl(optCtrl=list(maxfun=1e6)))
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## unable to evaluate scaled gradient
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge: degenerate Hessian with 1 negative eigenvalues
## Warning: Model failed to converge with 1 negative eigenvalue: -2.9e+02
model.RT.3.nest <- lmerTest::lmer(firstRT ~ catChoiceCondition / scaledMeanValue + catChoiceCondition / scaledValueDiff + scaledTrialNum + 
                     (1 + catChoiceCondition / scaledMeanValue + catChoiceCondition / scaledValueDiff + scaledTrialNum|participant),
                     data=df.total.rt.3,
                   control=lmerControl(optCtrl=list(maxfun=1e6)))
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 1 negative eigenvalue: -1.8e+02
model.acc.3 <- glmer(isWorstFirst ~ catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff +
                        scaledTrialNum + 
                     (1 + catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff +
                        scaledTrialNum|participant),
                     data=df.total.rt.3,family=binomial)
## boundary (singular) fit: see help('isSingular')
model.acc.3.dummy <- lmer(isWorstFirst ~ catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff +
                        scaledTrialNum + 
                     (1 + catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff +
                        scaledTrialNum|participant),
                     data=df.total.rt.3)
## boundary (singular) fit: see help('isSingular')
model.acc.3.nest <- lmer(isWorstFirst ~ catChoiceCondition / scaledMeanValue + catChoiceCondition / scaledValueDiff +
                        scaledTrialNum + 
                     (1 + catChoiceCondition / scaledMeanValue + catChoiceCondition / scaledValueDiff +
                        scaledTrialNum|participant),
                     data=df.total.rt.3)
## boundary (singular) fit: see help('isSingular')
tab_model(model.RT.3,model.acc.3,show.re.var = F,transform = NULL,pred.labels = c("Intercept","Inclusivity","Overall Value","Relative Value","Trial Order","Incl by OV","Incl by RV"),dv.labels = c("Reaction Time","Accuracy"))
  Reaction Time Accuracy
Predictors Estimates CI p Log-Odds CI p
Intercept 3.04 2.90 – 3.18 <0.001 -0.25 -0.34 – -0.16 <0.001
Inclusivity -0.13 -0.19 – -0.07 <0.001 -0.14 -0.23 – -0.06 0.001
Overall Value 0.43 0.38 – 0.47 <0.001 0.09 0.04 – 0.14 0.001
Relative Value -0.16 -0.19 – -0.13 <0.001 0.48 0.41 – 0.55 <0.001
Trial Order -0.16 -0.20 – -0.12 <0.001 -0.05 -0.09 – -0.01 0.023
Incl by OV 0.07 0.03 – 0.12 0.003 0.06 -0.03 – 0.15 0.165
Incl by RV -0.01 -0.05 – 0.04 0.761 -0.08 -0.17 – 0.01 0.070
ICC 0.33 0.07
N 98 participant 98 participant
Observations 11476 11476
Marginal R2 / Conditional R2 0.117 / 0.409 0.066 / 0.133
model.conflict.3 <- lmerTest::lmer(conflict ~ catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.valid.3)
## boundary (singular) fit: see help('isSingular')
model.conflict.3.coeff <- lmerTest::lmer(conflict ~ catChoiceCondition / poly(scaledMeanValue,2) + catChoiceCondition / scaledValueDiff + scaledTrialNum + 
                     (1 + catChoiceCondition / poly(scaledMeanValue,2) + catChoiceCondition / scaledValueDiff + scaledTrialNum|participant),
                     data=df.total.valid.3)
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 1 negative eigenvalue: -1.9e+02
tab_model(model.conflict.3,transform = NULL,show.re.var = F,pred.labels = c("Intercept","Inclusivity","Overall Value","Overall Value^2","Relative Value","Trial Order","Incl by OV","Incl by OV^2","Excl by RV"),dv.labels = c("Conflict"))
  Conflict
Predictors Estimates CI p
Intercept 2.21 2.12 – 2.30 <0.001
Inclusivity -0.08 -0.15 – -0.01 0.030
Overall Value 46.04 37.12 – 54.96 <0.001
Overall Value^2 20.84 16.61 – 25.06 <0.001
Relative Value -0.07 -0.10 – -0.03 <0.001
Trial Order -0.00 -0.03 – 0.03 0.951
Incl by OV 7.24 1.23 – 13.25 0.018
Incl by OV^2 -2.45 -7.29 – 2.40 0.322
Excl by RV 0.03 -0.01 – 0.07 0.195
N participant 98
Observations 11760
Marginal R2 / Conditional R2 0.241 / NA

4.3.0.1 Get prediction for two ORXOR studies

coeff.rt <- t(fixef(model.RT.3)['catChoiceConditionOR-XOR'])
df.ci <- confint(model.RT.3,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.rt <- df.ci['catChoiceConditionOR-XOR',]
estimate.rt <- cbind(coeff.rt,t(ci.rt))
colnames(estimate.rt)<-c('coeff','lower','upper')

coeff.acc <- t(fixef(model.acc.3.dummy)['catChoiceConditionOR-XOR'])
df.ci <- confint(model.acc.3.dummy,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.acc <- df.ci['catChoiceConditionOR-XOR',]
estimate.acc <- cbind(coeff.acc,t(ci.acc))
colnames(estimate.acc)<-c('coeff','lower','upper')

coeff.conf <- t(fixef(model.conflict.3)['catChoiceConditionOR-XOR'])
df.ci <- confint(model.conflict.3,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.conf <- df.ci['catChoiceConditionOR-XOR',]
estimate.conf <- cbind(coeff.conf,t(ci.conf))
colnames(estimate.conf)<-c('coeff','lower','upper')

estimate.all <- data.frame(rbind(estimate.rt,estimate.acc,estimate.conf))
estimate.all$var <- c('RT','Acc','Conflict')
p.diff.acc.3 <- ggplot(estimate.all %>% filter(var %in% c('Acc')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Inclusivity")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("Acc"='P(Worst First)')) + scale_y_continuous(limits = c(-0.1,0.004),breaks = c(-0.1,0))
p.diff.acc.3

p.diff.rt.3 <- ggplot(estimate.all %>% filter(var %in% c('RT')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Inclusivity")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("RT"='RT')) + 
  scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(-0.5,0.02),breaks = c(-0.5,0))
p.diff.rt.3

p.diff.conflict.3 <- ggplot(estimate.all %>% filter(var %in% c('Conflict')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Inclusivity")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("Conflict"='Conflict')) + scale_y_continuous(limits = c(-0.5,0.02),breaks = c(-0.5,0))
p.diff.conflict.3

eff_mv.RT.3 <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.RT.3,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.rt.3$scaledMeanValue,0.025),
                                                    quantile(df.total.rt.3$scaledMeanValue,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.mv.RT.3 <- as.data.frame(eff_mv.RT.3) %>% dplyr::mutate(study='Study 3')

p.eff.mv.rt.3<-ggplot(data=IA.mv.RT.3, aes(x=scaledMeanValue, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.RT.3, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall Value\n(z-scored)") + ylab("RT (sec)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))

p.eff.mv.rt.3

eff_vd.RT.3 <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.RT.3,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.rt.3$scaledValueDiff,0.025),
                                                    quantile(df.total.rt.3$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.vd.RT.3 <- as.data.frame(eff_vd.RT.3) %>% dplyr::mutate(study='Study 3')

p.eff.vd.rt.3<-ggplot(data=IA.vd.RT.3, aes(x=scaledValueDiff, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.RT.3, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("RT (sec)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))

p.eff.vd.rt.3

eff_mv.acc.3 <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.acc.3,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.rt.3$scaledMeanValue,0.025),
                                                    quantile(df.total.rt.3$scaledMeanValue,0.972),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.mv.acc.3 <- as.data.frame(eff_mv.acc.3) %>% dplyr::mutate(study='Study 3')

p.eff.mv.acc.3 <-ggplot(data=IA.mv.acc.3, aes(x=scaledMeanValue, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.acc.3, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab("P(Worst First)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(0.2,0.8)) + scale_y_continuous(breaks = c(0.2,0.8),labels=function(x) sprintf("%.1f", x))

p.eff.mv.acc.3

#ggsave('Study12_RT.pdf')
eff_vd.acc.3 <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.acc.3,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.rt.3$scaledValueDiff,0.025),
                                                    quantile(df.total.rt.3$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.vd.acc.3 <- as.data.frame(eff_vd.acc.3) %>% dplyr::mutate(study='Study 3')

p.eff.vd.acc.3<-ggplot(data=IA.vd.acc.3, aes(x=scaledValueDiff, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.acc.3, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("P(Worst First)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(0.2,0.8)) + scale_y_continuous(breaks = c(0.2,0.8),labels=function(x) sprintf("%.1f", x))

p.eff.vd.acc.3

#ggsave('Study12_RT.pdf')
eff_mv.cfl.3 <- Effect(c("scaledMeanValue","catChoiceCondition"),
                       model.conflict.3,
                       xlevels=list(scaledMeanValue=seq(quantile(df.total.valid.3$scaledMeanValue,0.025),
                                                        quantile(df.total.valid.3$scaledMeanValue,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledValueDiff, scaledTrialNum, scaledMeanValue are one-column
## matrices that were converted to vectors
IA.mv.cfl.3 <- as.data.frame(eff_mv.cfl.3) %>% dplyr::mutate(study='Study 3')

IA.mv.cfl <- IA.mv.cfl.3

IA.mv.cfl$catChoiceCondition <- relevel(IA.mv.cfl$catChoiceCondition,ref = 'XOR')

p.eff.mv.cfl.3<-ggplot(data=IA.mv.cfl, aes(x=scaledMeanValue, y=fit,group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.cfl, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab("Conflict") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + # ggtitle('Exclusive') +
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))

p.eff.mv.cfl.3

# ggsave('figures/ov_conflict_by_cond_d.pdf',width=4,height=2.5)
new.mv.1 <- seq(quantile(df.total.valid.3$scaledMeanValue,0.025),
                quantile(df.total.valid.3$scaledMeanValue,0.975),0.1)

eff.df.mv.3 <- marginalConflictMVEffect(model.conflict.3,df.total.valid.3$scaledMeanValue,new.mv.1) %>%
  dplyr::mutate(scaledMeanValue=x,
                catChoiceCondition='XOR - OR',
                fit= eff,
                upper= eff+ci,
                lower= eff-ci,
                se=NA,
                study='Study 3')

p.eff.cc.int.3<-ggplot(data=eff.df.mv.3, aes(x=x, y=fit)) + 
  geom_line(size=0.5)+theme_bw(12) +
  geom_ribbon(data=eff.df.mv.3, aes(x=x, max = upper, min = lower),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab('Effect of Inclusivity') +
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + geom_hline(yintercept=0,color='#555555') + 
  scale_fill_manual("",values=c("#005555","#550055")) + scale_color_manual("",values=c("#005555","#550055")) + # ggtitle('Exclusive - Non-Exclusive') +
  coord_cartesian(ylim=c(-0.8,0.2)) + scale_y_continuous(breaks = c(-0.8,0))

p.eff.cc.int.3

eff_vd.cfl.3 <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.conflict.3,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.rt.3$scaledValueDiff,0.025),
                                                    quantile(df.total.rt.3$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledValueDiff, scaledTrialNum, scaledMeanValue are one-column
## matrices that were converted to vectors
IA.vd.cfl <- as.data.frame(eff_vd.cfl.3) %>% dplyr::mutate(study='Study 1')

IA.vd.cfl$catChoiceCondition <- relevel(IA.vd.cfl$catChoiceCondition,ref = 'XOR')

p.eff.vd.cfl.3<-ggplot(data=IA.vd.cfl, aes(x=scaledValueDiff, y=fit,group=catChoiceCondition)) +
  geom_line(size=0.5,aes(color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.cfl, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("Conflict") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))

p.eff.vd.cfl.3

#ggsave('Study12_RT.pdf')
lay <- rbind(c(1,NA,2,NA,NA,3,3,NA),
             c(4,NA,5,NA,NA,6,6,NA),
             c(7,NA,8,NA,9,9,10,10))

plots <- list(p.diff.rt.3,p.eff.vd.rt.3,p.eff.mv.rt.3,
              p.diff.acc.3,p.eff.vd.acc.3,p.eff.mv.acc.3,
              p.diff.conflict.3,p.eff.vd.cfl.3,p.eff.mv.cfl.3,p.eff.cc.int.3)
grobs <- list()
widths <- list()
heights <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths
    heights[[i]] <- grobs[[i]]$heights
}

maxwidth <- do.call(grid::unit.pmax, widths)
maxheight <- do.call(grid::unit.pmax,heights)

for (i in 1:length(grobs)){
     grobs[[i]]$heights <- as.list(maxheight)
     grobs[[i]]$widths <- as.list(maxwidth)
}


for (i in 1:length(grobs)){
     grobs[[i]]$heights <- as.list(maxheight)
     grobs[[i]]$widths <- as.list(maxwidth)
}


p<-grid.arrange(grobs = grobs, layout_matrix = lay,widths=unit(c(2,0.1,2.7,0.1,0.8,1.35,1.35,0.8), c("cm", "cm")),heights=unit(c(3,3,3),c('cm','cm')))

ggsave(filename = '../Figures/Figure5_V3.pdf',p,units = 'cm',width = 25,height = 20)
df.total.rt.3$scaledRT<-scale(df.total.rt.3$firstRT)

model.conflict.3.rt <- lmerTest::lmer(conflict ~ scaledRT + acc + catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + scaledRT + acc + catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant), data=df.total.rt.3)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.0748015 (tol = 0.002, component 1)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model is nearly unidentifiable: large eigenvalue ratio
##  - Rescale variables?
tab_model(model.conflict.3.rt,show.re.var = FALSE,pred.labels = c('Intercept','RT','Accuracy','Inclusivity','OV','OV^2','RV','Trial Num','Incl by OV','Incl by OV^2','Excl by RV'))
  conflict
Predictors Estimates CI p
Intercept 2.20 2.10 – 2.30 <0.001
RT 0.13 0.09 – 0.16 <0.001
Accuracy 0.07 0.01 – 0.13 0.014
Inclusivity -0.08 -0.15 – -0.01 0.029
OV 39.80 31.56 – 48.03 <0.001
OV^2 18.80 14.79 – 22.82 <0.001
RV -0.05 -0.07 – -0.02 0.001
Trial Num 0.01 -0.03 – 0.04 0.692
Incl by OV 4.43 -1.55 – 10.40 0.147
Incl by OV^2 -3.50 -8.19 – 1.20 0.144
Excl by RV 0.03 -0.01 – 0.07 0.187
ICC 0.40
N participant 98
Observations 11476
Marginal R2 / Conditional R2 0.161 / 0.494
df.rating.new.s <- read.csv('../Data/Study3/Selection/Study3a_2.csv')

df.total.new.s <- read.csv('../Data/Study3/Selection/Study3a_1.csv') %>%
  mutate(catChoiceCondition=relevel(factor(catChoiceCondition),ref = 'XOR'),
         isBestFirst=firstValue==bestValue,
         scaledTrialNum=scale(trialN),
         scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff))

df.total.rt.new.s <- df.total.new.s %>% filter(firstRT>0.1,firstRT<18) %>%
  mutate(scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledTrialNum=scale(trialN))

contrasts(df.total.new.s$catChoiceCondition) <- contr.sdif
contrasts(df.total.rt.new.s$catChoiceCondition) <- contr.sdif

df.or.rt.new.s <- df.total.rt.new.s %>% filter(catChoiceCondition=='OR',NChosen>=1) %>%
    dplyr::mutate(scaledMeanValue=scale(meanValue),
                  scaledValueDiff=scale(valueDiff),
                  scaledTrialNum=scale(trialN),
                  scaledFirstRT=scale(firstRT),
                  acc=factor(isBestFirst))

contrasts(df.or.rt.new.s$acc)<-contr.sum
df.rating.new.d <- read.csv('../Data/Study3/Removal/Study3b_2.csv')

df.total.new.d <- read.csv('../Data/Study3/Removal/Study3b_1.csv') %>%
  mutate(catChoiceCondition=relevel(factor(catChoiceCondition),ref = 'XOR'),
         isWorstFirst=firstValue==worstValue,
         scaledTrialNum=scale(trialN),
         scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff))

df.total.rt.new.d <- df.total.new.d %>% filter(firstRT>0.1,firstRT<18) %>%
  mutate(scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledTrialNum=scale(trialN))


contrasts(df.total.new.d$catChoiceCondition) <- contr.sdif
contrasts(df.total.rt.new.d$catChoiceCondition) <- contr.sdif

df.or.rt.new.d <- df.total.rt.new.d %>% filter(catChoiceCondition=='OR',NChosen>=1) %>%
    dplyr::mutate(scaledMeanValue=scale(meanValue),
                  scaledValueDiff=scale(valueDiff),
                  scaledTrialNum=scale(trialN),
                  scaledFirstRT=scale(firstRT),
                  acc=factor(isWorstFirst))

contrasts(df.or.rt.new.d$acc)<-contr.sum
model.RT.ns <-  lmerTest::lmer(log10(firstRT) ~ catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.new.s)
## boundary (singular) fit: see help('isSingular')
model.RT.ns.r <-  lmerTest::lmer(firstRT ~ catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.new.s)
## boundary (singular) fit: see help('isSingular')
model.acc.ns <- glmer(isBestFirst ~ catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.new.s,family = binomial)
## boundary (singular) fit: see help('isSingular')
model.acc.ns.dummy <- lmerTest::lmer(isBestFirst ~ catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.new.s)
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 1 negative eigenvalue: -4.7e-01
model.rating.ns <- lmerTest::lmer(conflict ~ catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.new.s)
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 1 negative eigenvalue: -1.2e-02
tab_model(model.RT.ns,model.acc.ns,model.rating.ns,show.re.var = FALSE,transform = NULL,digits=3)
  log10(firstRT) isBestFirst conflict
Predictors Estimates CI p Log-Odds CI p Estimates CI p
(Intercept) 0.460 0.422 – 0.497 <0.001 -0.066 -0.174 – 0.043 0.235 2.469 2.320 – 2.617 <0.001
catChoiceConditionOR-XOR -0.017 -0.030 – -0.004 0.013 0.001 -0.103 – 0.105 0.983 -0.332 -0.488 – -0.176 <0.001
scaledMeanValue -0.061 -0.070 – -0.052 <0.001 0.078 0.014 – 0.141 0.016
scaledValueDiff -0.032 -0.039 – -0.025 <0.001 0.603 0.520 – 0.686 <0.001 -0.089 -0.132 – -0.046 <0.001
scaledTrialNum -0.035 -0.045 – -0.025 <0.001 -0.037 -0.093 – 0.018 0.191 0.001 -0.038 – 0.040 0.967
catChoiceConditionOR-XOR
× scaledMeanValue
-0.017 -0.028 – -0.007 0.001 0.031 -0.082 – 0.144 0.590
catChoiceConditionOR-XOR
× scaledValueDiff
-0.004 -0.013 – 0.005 0.391 -0.117 -0.241 – 0.008 0.066 -0.003 -0.066 – 0.060 0.930
scaledMeanValue [1st
degree]
-2.857 -16.168 – 10.454 0.674
scaledMeanValue [2nd
degree]
13.391 8.113 – 18.670 <0.001
catChoiceConditionOR-XOR
× scaledMeanValue [1st
degree]
-13.923 -22.255 – -5.592 0.001
catChoiceConditionOR-XOR
× scaledMeanValue [2nd
degree]
-3.965 -10.023 – 2.093 0.200
ICC 0.44    
N 59 participant 59 participant 59 participant
Observations 7045 7045 7080
Marginal R2 / Conditional R2 0.089 / 0.490 0.098 / NA 0.083 / NA
model.RT.nd <- lmerTest::lmer(log10(firstRT) ~ catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.new.d)
## boundary (singular) fit: see help('isSingular')
model.RT.nd.r <- lmerTest::lmer(firstRT ~ catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.new.d)
## boundary (singular) fit: see help('isSingular')
model.acc.nd <- glmer(isWorstFirst ~ catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.new.d,family = binomial)
## boundary (singular) fit: see help('isSingular')
model.acc.nd.dummy <- lmerTest::lmer(isWorstFirst ~ catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.new.d)
## boundary (singular) fit: see help('isSingular')
model.rating.nd <- lmerTest::lmer(conflict ~ catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition *  poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.new.d)
## boundary (singular) fit: see help('isSingular')
tab_model(model.RT.nd,model.acc.nd,model.rating.nd,show.re.var = FALSE,transform = NULL)
  log10(firstRT) isWorstFirst conflict
Predictors Estimates CI p Log-Odds CI p Estimates CI p
(Intercept) 0.45 0.41 – 0.49 <0.001 -0.06 -0.16 – 0.05 0.299 2.34 2.21 – 2.47 <0.001
catChoiceConditionOR-XOR -0.01 -0.03 – -0.00 0.013 -0.05 -0.16 – 0.05 0.324 -0.08 -0.18 – 0.03 0.174
scaledMeanValue 0.07 0.06 – 0.08 <0.001 0.09 0.01 – 0.16 0.031
scaledValueDiff -0.03 -0.03 – -0.02 <0.001 0.62 0.54 – 0.70 <0.001 -0.08 -0.12 – -0.04 <0.001
scaledTrialNum -0.03 -0.04 – -0.02 <0.001 -0.01 -0.06 – 0.04 0.617 0.00 -0.03 – 0.03 0.965
catChoiceConditionOR-XOR
× scaledMeanValue
0.02 0.01 – 0.03 <0.001 0.10 -0.01 – 0.22 0.069
catChoiceConditionOR-XOR
× scaledValueDiff
-0.00 -0.01 – 0.01 0.738 0.04 -0.09 – 0.16 0.563 -0.02 -0.07 – 0.03 0.360
scaledMeanValue [1st
degree]
50.71 42.68 – 58.73 <0.001
scaledMeanValue [2nd
degree]
16.24 11.89 – 20.60 <0.001
catChoiceConditionOR-XOR
× scaledMeanValue [1st
degree]
5.98 1.32 – 10.64 0.012
catChoiceConditionOR-XOR
× scaledMeanValue [2nd
degree]
0.15 -4.88 – 5.19 0.952
ICC   0.07  
N 61 participant 61 participant 61 participant
Observations 7279 7279 7320
Marginal R2 / Conditional R2 0.168 / NA 0.100 / 0.160 0.357 / NA
tab_model(model.RT.ns.r,model.RT.nd.r,pred.labels = c("Intercept","Inclusivity","Overall Value","Relative Value","Trial Order","Incl by OV","Incl by RV"),dv.labels = c("Replication Study-Selection RT","Replication Study-Removal RT"),show.re.var = F,show.icc = F,show.r2 = F,show.ngroups = F,show.obs = F)
  Replication Study-Selection RT Replication Study-Removal RT
Predictors Estimates CI p Estimates CI p
Intercept 3.38 3.09 – 3.68 <0.001 3.34 3.08 – 3.61 <0.001
Inclusivity -0.14 -0.25 – -0.03 0.010 -0.10 -0.20 – -0.00 0.044
Overall Value -0.49 -0.59 – -0.39 <0.001 0.51 0.44 – 0.58 <0.001
Relative Value -0.28 -0.35 – -0.21 <0.001 -0.26 -0.32 – -0.20 <0.001
Trial Order -0.25 -0.32 – -0.19 <0.001 -0.25 -0.31 – -0.18 <0.001
Incl by OV -0.15 -0.25 – -0.05 0.004 0.13 0.04 – 0.23 0.005
Incl by RV -0.02 -0.10 – 0.07 0.723 -0.02 -0.10 – 0.07 0.709
tab_model(model.RT.ns,model.RT.nd,pred.labels = c("Intercept","Inclusivity","Overall Value","Relative Value","Trial Order","Incl by OV","Incl by RV"),dv.labels = c("Replication Study-Selection log(RT)","Replication Study-Removal log(RT)"),show.re.var = F,show.icc = F,show.r2 = F,show.ngroups = F,show.obs = F)
  Replication Study-Selection log(RT) Replication Study-Removal log(RT)
Predictors Estimates CI p Estimates CI p
Intercept 0.46 0.42 – 0.50 <0.001 0.45 0.41 – 0.49 <0.001
Inclusivity -0.02 -0.03 – -0.00 0.013 -0.01 -0.03 – -0.00 0.013
Overall Value -0.06 -0.07 – -0.05 <0.001 0.07 0.06 – 0.08 <0.001
Relative Value -0.03 -0.04 – -0.03 <0.001 -0.03 -0.03 – -0.02 <0.001
Trial Order -0.03 -0.04 – -0.02 <0.001 -0.03 -0.04 – -0.02 <0.001
Incl by OV -0.02 -0.03 – -0.01 0.001 0.02 0.01 – 0.03 <0.001
Incl by RV -0.00 -0.01 – 0.01 0.391 -0.00 -0.01 – 0.01 0.738
coeff.rt.ns <- fixef(model.RT.ns)[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff')]
df.ci <- confint(model.RT.ns,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.rt <- df.ci[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff'),]
estimate.rt.ns <- t(rbind(coeff.rt.ns,t(ci.rt)))
colnames(estimate.rt.ns)<-c('coeff','lower','upper')
rownames(estimate.rt.ns) <- NULL
estimate.rt.ns <- data.frame(estimate.rt.ns)
estimate.rt.ns$params <- c('Incl - Excl','(Incl - Excl) X OV','(Incl - Excl) X RV')
estimate.rt.ns$dv <- 'RT'

coeff.acc.ns <- fixef(model.acc.ns)[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff')]
df.ci <- confint(model.acc.ns,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.acc <- df.ci[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff'),]
estimate.acc.ns <- t(rbind(coeff.acc.ns,t(ci.acc)))
colnames(estimate.acc.ns)<-c('coeff','lower','upper')
rownames(estimate.acc.ns) <- NULL
estimate.acc.ns <- data.frame(estimate.acc.ns)
estimate.acc.ns$params <- c('Incl - Excl','(Incl - Excl) X OV','(Incl - Excl) X RV')
estimate.acc.ns$dv <- 'P(Best First)'

estimate.rt.acc.ns <- rbind(estimate.rt.ns,estimate.acc.ns)
estimate.rt.acc.ns$order <- seq(1,6)
estimate.rt.acc.ns$study <- 'Selection'

coeff.rt.nd <- fixef(model.RT.nd)[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff')]
df.ci <- confint(model.RT.nd,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.rt <- df.ci[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff'),]
estimate.rt.nd <- t(rbind(coeff.rt.nd,t(ci.rt)))
colnames(estimate.rt.nd)<-c('coeff','lower','upper')
rownames(estimate.rt.nd) <- NULL
estimate.rt.nd <- data.frame(estimate.rt.nd)
estimate.rt.nd$params <- c('Incl - Excl','(Incl - Excl) X OV','(Incl - Excl) X RV')
estimate.rt.nd$dv <- 'RT'

coeff.acc.nd <- fixef(model.acc.nd)[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff')]
df.ci <- confint(model.acc.nd,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.acc <- df.ci[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff'),]
estimate.acc.nd <- t(rbind(coeff.acc.nd,t(ci.acc)))
colnames(estimate.acc.nd)<-c('coeff','lower','upper')
rownames(estimate.acc.nd) <- NULL
estimate.acc.nd <- data.frame(estimate.acc.nd)
estimate.acc.nd$params <- c('Incl - Excl','(Incl - Excl) X OV','(Incl - Excl) X RV')
estimate.acc.nd$dv <- 'P(Best First)'

estimate.rt.acc.nd <- rbind(estimate.rt.nd,estimate.acc.nd)
estimate.rt.acc.nd$order <- seq(1,6)
estimate.rt.acc.nd$study <- 'Deselection'

estimate.rt.acc.new <- rbind(estimate.rt.acc.ns,estimate.rt.acc.nd)
estimate.rt.acc.new$params <- factor(estimate.rt.acc.new$params,
                                     levels = c('(Incl - Excl) X RV','(Incl - Excl) X OV','Incl - Excl'))
p.summary.new.acc <- ggplot(estimate.rt.acc.new %>% filter(dv=='P(Best First)'),aes(x=params,y=coeff,group=study,color=study)) + geom_hline(yintercept=0,color='#AAAAAA',size=0.2) + geom_point(position = position_dodge(0.6),size=0.5,aes(shape=study)) + geom_errorbar(position = position_dodge(0.6),aes(ymin=lower,ymax=upper),width=0.2) + coord_flip() + theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") + scale_y_continuous(limits = c(-0.5,0.5),breaks = c(-0.5,0,0.5)) +  scale_color_manual("",values=c('#222222','#AA0000')) + xlab('') + ylab('') + scale_x_discrete(labels=c('Incl - Excl'='On intercept',
                                                                                                                                                                                                                                          '(Incl - Excl) X OV'='On overall value effect','(Incl - Excl) X RV'='On relative value effect'))

p.summary.new.acc

p.summary.new.rt <- ggplot(estimate.rt.acc.new %>% filter(dv=='RT'),aes(x=params,y=coeff,group=study,color=study)) + geom_hline(yintercept=0,color='#AAAAAA',size=0.2) + geom_point(position = position_dodge(0.6),size=1,aes(shape=study)) + geom_errorbar(position = position_dodge(0.6),aes(ymin=lower,ymax=upper),width=0.2,linewidth=0.5) + coord_flip() + theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") + scale_y_continuous(limits = c(-0.04,0.04),breaks = c(-0.04,0,0.04)) + scale_color_manual("",values=c('#AA0000','#222222')) + xlab('') + ylab('') + scale_x_discrete(labels=c('Incl - Excl'='On intercept',
                                                                                                                                                                                                                                          '(Incl - Excl) X OV'='On overall value effect','(Incl - Excl) X RV'='On relative value effect'))
p.summary.new.rt

ggsave(filename = '../Figures/Figure7A.pdf',p.summary.new.rt,units = 'cm',width = 5,height = 3)
new.mv.1 <- seq(min(quantile(df.total.rt.new.s$scaledMeanValue,0.025),
                    quantile(df.total.rt.new.d$scaledMeanValue,0.025)),
                max(quantile(df.total.rt.new.s$scaledMeanValue,0.975),
                    quantile(df.total.rt.new.d$scaledMeanValue,0.975)),0.1)

eff.df.mv.ns <- marginalConflictMVEffect(model.rating.ns,df.total.rt.new.s$scaledMeanValue,new.mv.1) %>%
  dplyr::mutate(scaledMeanValue=x,
                catChoiceCondition='XOR - OR',
                fit=eff,
                upper=eff+ci,
                lower=eff-ci,
                se=NA,
                study='Selection')

eff.df.mv.nd <- marginalConflictMVEffect(model.rating.nd,df.total.rt.new.d$scaledMeanValue,new.mv.1) %>%
  dplyr::mutate(scaledMeanValue=x,
                catChoiceCondition='XOR - OR',
                fit=eff,
                upper=eff+ci,
                lower=eff-ci,
                se=NA,
                study='Deselection')


eff.df.mv.new <- rbind(eff.df.mv.ns,eff.df.mv.nd)

p.eff.cc.int.new<-ggplot(data=eff.df.mv.new, aes(x=x, y=fit,group=study)) + geom_hline(yintercept=0,color='#AAAAAA',size=0.2) + 
  geom_line(size=0.5,aes(color=study))+theme_bw(12) +
  geom_ribbon(aes(x=x, max = upper, min = lower,fill=study),alpha=0.3)+ 
  xlab("Overall value\n(z-scored)") + ylab('Effect of Inclusivity') +
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),strip.text.y = element_blank()) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c("#AA0000","#222222")) + scale_color_manual("",values=c("#AA0000","#222222")) + # ggtitle('Exclusive - Non-Exclusive') +
  coord_cartesian(ylim=c(-1,0.2)) + scale_y_continuous(breaks = c(-1,0))

p.eff.cc.int.new

ggsave(filename = '../Figures/Figure7B.pdf',p.eff.cc.int.new,units = 'cm',width = 3,height = 3)
coeff.rt <- t(fixef(model.RT.ns)['catChoiceConditionOR-XOR'])
df.ci <- confint(model.RT.ns,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.rt <- df.ci['catChoiceConditionOR-XOR',]
estimate.rt <- cbind(coeff.rt,t(ci.rt))
colnames(estimate.rt)<-c('coeff','lower','upper')

coeff.acc <- t(fixef(model.acc.ns.dummy)['catChoiceConditionOR-XOR'])
df.ci <- confint(model.acc.ns.dummy,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.acc <- df.ci['catChoiceConditionOR-XOR',]
estimate.acc <- cbind(coeff.acc,t(ci.acc))
colnames(estimate.acc)<-c('coeff','lower','upper')

coeff.conf <- t(fixef(model.rating.ns)['catChoiceConditionOR-XOR'])
df.ci <- confint(model.rating.ns,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.conf <- df.ci['catChoiceConditionOR-XOR',]
estimate.conf <- cbind(coeff.conf,t(ci.conf))
colnames(estimate.conf)<-c('coeff','lower','upper')

estimate.all <- data.frame(rbind(estimate.rt,estimate.acc,estimate.conf))
estimate.all$var <- c('RT','Acc','Conflict')
p.diff.acc.ns <- ggplot(estimate.all %>% filter(var %in% c('Acc')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Inclusivity")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("Acc"='P(Best First)')) + scale_y_continuous(limits = c(-0.05,0.05),breaks = c(-0.05,0.05))

p.diff.acc.ns

p.diff.rt.ns <- ggplot(estimate.all %>% filter(var %in% c('RT')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Inclusivity")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("RT"='log(RT)')) + scale_y_continuous(limits = c(-0.05,0.005),breaks = c(-0.05,0))

p.diff.rt.ns

p.diff.conflict.ns <- ggplot(estimate.all %>% filter(var %in% c('Conflict')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Inclusivity")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("Conflict"='Conflict')) + scale_y_continuous(limits = c(-0.5,0.02),breaks = c(-0.5,0))
p.diff.conflict.ns

eff_mv.RT.ns <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.RT.ns,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.rt.new.s$scaledMeanValue,0.025),
                                                    quantile(df.total.rt.new.s$scaledMeanValue,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.mv.RT.ns <- as.data.frame(eff_mv.RT.ns) %>% dplyr::mutate(study='Study 3')

p.eff.mv.rt.ns<-ggplot(data=IA.mv.RT.ns, aes(x=scaledMeanValue, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.RT.ns, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall Value\n(z-scored)") + ylab("RT (Log-Transformed)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(.3,.7)) + scale_y_continuous(breaks = c(.3,.7))

p.eff.mv.rt.ns

eff_vd.RT.ns <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.RT.ns,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.rt.new.s$scaledValueDiff,0.025),
                                                    quantile(df.total.rt.new.s$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.vd.RT.ns <- as.data.frame(eff_vd.RT.ns) %>% dplyr::mutate(study='Study 3')

p.eff.vd.rt.ns<-ggplot(data=IA.vd.RT.ns, aes(x=scaledValueDiff, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.RT.ns, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("RT (Log-Transformed)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(.3,.7)) + scale_y_continuous(breaks = c(.3,.7))

p.eff.vd.rt.ns

eff_mv.acc.ns <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.acc.ns,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.rt.new.s$scaledMeanValue,0.025),
                                                    quantile(df.total.rt.new.s$scaledMeanValue,0.972),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.mv.acc.ns <- as.data.frame(eff_mv.acc.ns) %>% dplyr::mutate(study='Study 3')

p.eff.mv.acc.ns <-ggplot(data=IA.mv.acc.ns, aes(x=scaledMeanValue, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.acc.ns, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab("P(Best First)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(0.1,0.9)) + scale_y_continuous(breaks = c(0.1,0.9),labels=function(x) sprintf("%.1f", x))

p.eff.mv.acc.ns

#ggsave('Study12_RT.pdf')
eff_vd.acc.ns <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.acc.ns,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.rt.new.s$scaledValueDiff,0.025),
                                                    quantile(df.total.rt.new.s$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.vd.acc.ns <- as.data.frame(eff_vd.acc.ns) %>% dplyr::mutate(study='Study 3')

p.eff.vd.acc.ns<-ggplot(data=IA.vd.acc.ns, aes(x=scaledValueDiff, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.acc.ns, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("P(Best First)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(0.1,0.9)) + scale_y_continuous(breaks = c(0.1,0.9),labels=function(x) sprintf("%.1f", x))

p.eff.vd.acc.ns

#ggsave('Study12_RT.pdf')
lay <- rbind(c(1,NA,2,NA,3),
             c(4,NA,5,NA,6))

plots <- list(p.diff.rt.ns,p.eff.mv.rt.ns,p.eff.vd.rt.ns,
              p.diff.acc.ns,p.eff.mv.acc.ns,p.eff.vd.acc.ns)
grobs <- list()
widths <- list()
heights <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths
    heights[[i]] <- grobs[[i]]$heights
}

maxwidth <- do.call(grid::unit.pmax, widths)
maxheight <- do.call(grid::unit.pmax,heights)

for (i in 1:length(grobs)){
     grobs[[i]]$heights <- as.list(maxheight)
     grobs[[i]]$widths <- as.list(maxwidth)
}


for (i in 1:length(grobs)){
     grobs[[i]]$heights <- as.list(maxheight)
     grobs[[i]]$widths <- as.list(maxwidth)
}


p<-grid.arrange(grobs = grobs, layout_matrix = lay,widths=unit(c(2,0.1,2.7,0.1,2.7), c("cm", "cm")),heights=unit(c(3,3),c('cm','cm')))

ggsave(filename = '../Figures/FigureS1.pdf',p,units = 'cm',width = 20,height = 12)
coeff.rt <- t(fixef(model.RT.nd)['catChoiceConditionOR-XOR'])
df.ci <- confint(model.RT.nd,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.rt <- df.ci['catChoiceConditionOR-XOR',]
estimate.rt <- cbind(coeff.rt,t(ci.rt))
colnames(estimate.rt)<-c('coeff','lower','upper')

coeff.acc <- t(fixef(model.acc.nd.dummy)['catChoiceConditionOR-XOR'])
df.ci <- confint(model.acc.nd.dummy,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.acc <- df.ci['catChoiceConditionOR-XOR',]
estimate.acc <- cbind(coeff.acc,t(ci.acc))
colnames(estimate.acc)<-c('coeff','lower','upper')

coeff.conf <- t(fixef(model.rating.nd)['catChoiceConditionOR-XOR'])
df.ci <- confint(model.rating.nd,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.conf <- df.ci['catChoiceConditionOR-XOR',]
estimate.conf <- cbind(coeff.conf,t(ci.conf))
colnames(estimate.conf)<-c('coeff','lower','upper')

estimate.all <- data.frame(rbind(estimate.rt,estimate.acc,estimate.conf))
estimate.all$var <- c('RT','Acc','Conflict')
p.diff.acc.nd <- ggplot(estimate.all %>% filter(var %in% c('Acc')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Inclusivity")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("Acc"='P(Worst First)')) + scale_y_continuous(limits = c(-0.05,0.05),breaks = c(-0.05,0.05))

p.diff.acc.nd

p.diff.rt.nd <- ggplot(estimate.all %>% filter(var %in% c('RT')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Inclusivity")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("RT"='log(RT)')) + 
  scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(-0.05,0.005),breaks = c(-0.05,0))

p.diff.rt.nd

p.diff.conflict.nd <- ggplot(estimate.all %>% filter(var %in% c('Conflict')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Inclusivity")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("Conflict"='Conflict')) + 
  scale_color_manual(values=c('#0673C3','#00B024')) + scale_y_continuous(limits = c(-0.5,0.1),breaks = c(-0.5,0))
p.diff.conflict.nd

eff_mv.RT.nd <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.RT.nd,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.rt.new.s$scaledMeanValue,0.025),
                                                    quantile(df.total.rt.new.s$scaledMeanValue,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.mv.RT.nd <- as.data.frame(eff_mv.RT.nd) %>% dplyr::mutate(study='Study 3')

p.eff.mv.rt.nd<-ggplot(data=IA.mv.RT.nd, aes(x=scaledMeanValue, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.RT.nd, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall Value\n(z-scored)") + ylab("RT (Log-Transformed)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(.2,.7)) + scale_y_continuous(breaks = c(.2,.7))

p.eff.mv.rt.nd

eff_vd.RT.nd <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.RT.nd,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.rt.new.s$scaledValueDiff,0.025),
                                                    quantile(df.total.rt.new.s$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.vd.RT.nd <- as.data.frame(eff_vd.RT.nd) %>% dplyr::mutate(study='Study 3')

p.eff.vd.rt.nd<-ggplot(data=IA.vd.RT.nd, aes(x=scaledValueDiff, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.RT.nd, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("RT (Log-Transformed)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(.2,.7)) + scale_y_continuous(breaks = c(.2,.7))

p.eff.vd.rt.nd

eff_mv.acc.nd <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.acc.nd,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.rt.new.s$scaledMeanValue,0.025),
                                                    quantile(df.total.rt.new.s$scaledMeanValue,0.972),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.mv.acc.nd <- as.data.frame(eff_mv.acc.nd) %>% dplyr::mutate(study='Study 3')

p.eff.mv.acc.nd <-ggplot(data=IA.mv.acc.nd, aes(x=scaledMeanValue, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.acc.nd, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab("P(Worst First)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(0.1,0.9)) + scale_y_continuous(breaks = c(0.1,0.9),labels=function(x) sprintf("%.1f", x))

p.eff.mv.acc.nd

#ggsave('Study12_RT.pdf')
eff_vd.acc.nd <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.acc.nd,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.rt.new.s$scaledValueDiff,0.025),
                                                    quantile(df.total.rt.new.s$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.vd.acc.nd <- as.data.frame(eff_vd.acc.nd) %>% dplyr::mutate(study='Study 3')

p.eff.vd.acc.nd<-ggplot(data=IA.vd.acc.nd, aes(x=scaledValueDiff, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.acc.nd, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("P(Worst First)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + 
  coord_cartesian(ylim=c(0.1,0.9)) + scale_y_continuous(breaks = c(0.1,0.9),labels=function(x) sprintf("%.1f", x))

p.eff.vd.acc.nd

#ggsave('Study12_RT.pdf')
lay <- rbind(c(1,NA,2,NA,3),
             c(4,NA,5,NA,6))

plots <- list(p.diff.rt.nd,p.eff.mv.rt.nd,p.eff.vd.rt.nd,
              p.diff.acc.nd,p.eff.mv.acc.nd,p.eff.vd.acc.nd)
grobs <- list()
widths <- list()
heights <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths
    heights[[i]] <- grobs[[i]]$heights
}

maxwidth <- do.call(grid::unit.pmax, widths)
maxheight <- do.call(grid::unit.pmax,heights)

for (i in 1:length(grobs)){
     grobs[[i]]$heights <- as.list(maxheight)
     grobs[[i]]$widths <- as.list(maxwidth)
}


for (i in 1:length(grobs)){
     grobs[[i]]$heights <- as.list(maxheight)
     grobs[[i]]$widths <- as.list(maxwidth)
}


p<-grid.arrange(grobs = grobs, layout_matrix = lay,widths=unit(c(2,0.1,2.7,0.1,2.7), c("cm", "cm")),heights=unit(c(3,3),c('cm','cm')))

ggsave(filename = '../Figures/FigureS2.pdf',p,units = 'cm',width = 20,height = 12)
eff_mv.cfl.ns <- Effect(c("scaledMeanValue","catChoiceCondition"),
                       model.rating.ns,
                       xlevels=list(scaledMeanValue=seq(quantile(df.total.new.s$scaledMeanValue,0.025),
                                                        quantile(df.total.new.s$scaledMeanValue,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledValueDiff, scaledTrialNum, scaledMeanValue are one-column
## matrices that were converted to vectors
IA.mv.cfl.ns <- as.data.frame(eff_mv.cfl.ns) %>% dplyr::mutate(study='Study 3')

IA.mv.cfl <- IA.mv.cfl.ns

IA.mv.cfl$catChoiceCondition <- relevel(IA.mv.cfl$catChoiceCondition,ref = 'XOR')

p.eff.mv.cfl.ns<-ggplot(data=IA.mv.cfl, aes(x=scaledMeanValue, y=fit,group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.cfl, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab("Conflict") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + # ggtitle('Exclusive') +
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))

p.eff.mv.cfl.ns

# ggsave('figures/ov_conflict_by_cond_d.pdf',width=4,height=2.5)
new.mv.1 <- seq(quantile(df.total.new.s$scaledMeanValue,0.025),
                quantile(df.total.new.s$scaledMeanValue,0.975),0.1)

eff.df.mv.ns <- marginalConflictMVEffect(model.rating.ns,df.total.rt.new.s$scaledMeanValue,new.mv.1) %>%
  dplyr::mutate(scaledMeanValue=x,
                catChoiceCondition='XOR - OR',
                fit= eff,
                upper= eff+ci,
                lower= eff-ci,
                se=NA,
                study='Study 3')

p.eff.cc.int.ns<-ggplot(data=eff.df.mv.ns, aes(x=x, y=fit)) + 
  geom_line(size=0.5)+theme_bw(12) +
  geom_ribbon(data=eff.df.mv.ns, aes(x=x, max = upper, min = lower),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab('Effect of Inclusivity') +
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  scale_fill_manual("",values=c("#005555","#550055")) + scale_color_manual("",values=c("#005555","#550055")) + # ggtitle('Exclusive - Non-Exclusive') +
  coord_cartesian(ylim=c(-1,0.2)) + scale_y_continuous(breaks = c(-1,0))

p.eff.cc.int.ns

eff_vd.cfl.ns <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.rating.ns,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.new.s$scaledValueDiff,0.025),
                                                    quantile(df.total.new.s$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledValueDiff, scaledTrialNum, scaledMeanValue are one-column
## matrices that were converted to vectors
IA.vd.cfl <- as.data.frame(eff_vd.cfl.ns) %>% dplyr::mutate(study='Study 1')

IA.vd.cfl$catChoiceCondition <- relevel(IA.vd.cfl$catChoiceCondition,ref = 'XOR')

p.eff.vd.cfl.ns<-ggplot(data=IA.vd.cfl, aes(x=scaledValueDiff, y=fit,group=catChoiceCondition)) +
  geom_line(size=0.5,aes(color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.cfl, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("Conflict") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024','#008012')) + 
  scale_color_manual("",values=c('#0673C3','#00B024','#008012')) + 
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))

p.eff.vd.cfl.ns

#ggsave('Study12_RT.pdf')
lay <- rbind(c(1,NA,2,NA,3,NA,4))

plots <- list(p.diff.conflict.ns,p.eff.mv.cfl.ns,p.eff.cc.int.ns,p.eff.vd.cfl.ns)
grobs <- list()
widths <- list()
heights <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths
    heights[[i]] <- grobs[[i]]$heights
}

maxwidth <- do.call(grid::unit.pmax, widths)
maxheight <- do.call(grid::unit.pmax, heights)

for (i in 1:length(grobs)){
  grobs[[i]]$widths <- as.list(maxwidth)
  grobs[[i]]$heights <- as.list(maxheight)
}

p<-grid.arrange(grobs = grobs, layout_matrix = lay,widths=unit(c(1.8,0.1,2.7,0.1,2.7,0.1,2.7), c("cm", "cm")),heights=unit(c(3),c('cm','cm')))

ggsave(filename = '../Figures/FigureS3.pdf',p,units = 'cm',width = 25,height = 12)
eff_mv.cfl.nd <- Effect(c("scaledMeanValue","catChoiceCondition"),
                       model.rating.nd,
                       xlevels=list(scaledMeanValue=seq(quantile(df.total.new.d$scaledMeanValue,0.025),
                                                        quantile(df.total.new.d$scaledMeanValue,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledValueDiff, scaledTrialNum, scaledMeanValue are one-column
## matrices that were converted to vectors
IA.mv.cfl.nd <- as.data.frame(eff_mv.cfl.nd) %>% dplyr::mutate(study='Study 3')

IA.mv.cfl <- IA.mv.cfl.nd

IA.mv.cfl$catChoiceCondition <- relevel(IA.mv.cfl$catChoiceCondition,ref = 'XOR')

p.eff.mv.cfl.nd<-ggplot(data=IA.mv.cfl, aes(x=scaledMeanValue, y=fit,group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.cfl, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab("Conflict") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024')) + # ggtitle('Exclusive') +
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))

p.eff.mv.cfl.nd

# ggsave('figures/ov_conflict_by_cond_d.pdf',width=4,height=2.5)
new.mv.1 <- seq(quantile(df.total.new.d$scaledMeanValue,0.025),
                quantile(df.total.new.d$scaledMeanValue,0.975),0.1)

eff.df.mv.nd <- marginalConflictMVEffect(model.rating.nd,df.total.new.d$scaledMeanValue,new.mv.1) %>%
  dplyr::mutate(scaledMeanValue=x,
                catChoiceCondition='XOR - OR',
                fit= eff,
                upper= eff+ci,
                lower= eff-ci,
                se=NA,
                study='Study 3')

p.eff.cc.int.nd<-ggplot(data=eff.df.mv.nd, aes(x=x, y=fit)) + 
  geom_line(size=0.5)+theme_bw(12) +
  geom_ribbon(data=eff.df.mv.nd, aes(x=x, max = upper, min = lower),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab('Effect of Inclusivity') +
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  scale_fill_manual("",values=c("#005555","#550055")) + scale_color_manual("",values=c("#005555","#550055")) + # ggtitle('Exclusive - Non-Exclusive') +
  coord_cartesian(ylim=c(-1,0.2)) + scale_y_continuous(breaks = c(-1,0))

p.eff.cc.int.nd

eff_vd.cfl.nd <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.rating.nd,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.new.d$scaledValueDiff,0.025),
                                                    quantile(df.total.new.d$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledValueDiff, scaledTrialNum, scaledMeanValue are one-column
## matrices that were converted to vectors
IA.vd.cfl <- as.data.frame(eff_vd.cfl.nd) %>% dplyr::mutate(study='Study 1')

IA.vd.cfl$catChoiceCondition <- relevel(IA.vd.cfl$catChoiceCondition,ref = 'XOR')

p.eff.vd.cfl.nd<-ggplot(data=IA.vd.cfl, aes(x=scaledValueDiff, y=fit,group=catChoiceCondition)) +
  geom_line(size=0.5,aes(color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.cfl, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("Conflict") + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#00B024','#008012')) + 
  scale_color_manual("",values=c('#0673C3','#00B024','#008012')) + 
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))

p.eff.vd.cfl.nd

#ggsave('Study12_RT.pdf')
lay <- rbind(c(1,NA,2,NA,3,NA,4))

plots <- list(p.diff.conflict.nd,p.eff.mv.cfl.nd,p.eff.cc.int.nd,p.eff.vd.cfl.nd)
grobs <- list()
widths <- list()
heights <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths
    heights[[i]] <- grobs[[i]]$heights
}

maxwidth <- do.call(grid::unit.pmax, widths)
maxheight <- do.call(grid::unit.pmax, heights)

for (i in 1:length(grobs)){
  grobs[[i]]$widths <- as.list(maxwidth)
  grobs[[i]]$heights <- as.list(maxheight)
}

p<-grid.arrange(grobs = grobs, layout_matrix = lay,widths=unit(c(1.8,0.1,2.7,0.1,2.7,0.1,2.7), c("cm", "cm")),heights=unit(c(3),c('cm','cm')))

ggsave(filename = '../Figures/FigureS4.pdf',p,units = 'cm',width = 25,height = 12)

5 All about the voluntary choices

df.or.rt.12 <- df.total.rt.12 %>% filter(catChoiceCondition=='OR') %>%
    dplyr::mutate(scaledMeanValue=scale(meanValue),
                  scaledValueDiff=scale(valueDiff),
                  scaledTrialNum=scale(trialN),
                  scaledFirstRT=scale(firstRT))


df.or.rt.3 <- df.total.rt.3 %>% filter(catChoiceCondition=='OR') %>%
    dplyr::mutate(scaledMeanValue=scale(meanValue),
                  scaledValueDiff=scale(valueDiff),
                  scaledTrialNum=scale(trialN),
                  scaledFirstRT=scale(firstRT))
df.or.rt.12.kept <- inner_join(df.or.rt.12,
                               rbind(df.rating.1.summary,df.rating.2.summary),by='participant') %>% 
  rowwise() %>%
  dplyr::mutate(valueKept = getMeanChosen(c(Value1,Value2,Value3,Value4),
                                          c(Order1,Order2,Order3,Order4)),
                minKept=getMinChosen(c(Value1,Value2,Value3,Value4),
                                     c(Order1,Order2,Order3,Order4)),
                NUFKept=getNUFChosen(c(Value1,Value2,Value3,Value4),
                                     c(Order1,Order2,Order3,Order4),
                                     medianValue),
                NUFKept2=getNUFChosen(c(Value1,Value2,Value3,Value4),
                                     c(Order1,Order2,Order3,Order4),
                                     avgValue),
                NUF=getNUF(c(Value1,Value2,Value3,Value4),medianValue),
                NUF2=getNUF(c(Value1,Value2,Value3,Value4),avgValue)) %>% ungroup()

# df.or.rt.12.kept <- inner_join(df.or.rt.12.kept,rbind(df.rating.1.summary,df.rating.2.summary),by='participant')

df.or.rt.new.s.kept <- inner_join(df.or.rt.new.s,df.rating.new.s,by='participant') %>% rowwise() %>%
  dplyr::mutate(valueKept = getMeanChosen(c(Value1,Value2,Value3,Value4),
                                          c(Order1,Order2,Order3,Order4)),
                minKept=getMinChosen(c(Value1,Value2,Value3,Value4),
                                     c(Order1,Order2,Order3,Order4)),
                NUFKept=getNUFChosen(c(Value1,Value2,Value3,Value4),
                                     c(Order1,Order2,Order3,Order4),
                                     medianValue),
                NUFKept2=getNUFChosen(c(Value1,Value2,Value3,Value4),
                                     c(Order1,Order2,Order3,Order4),
                                     avgValue),
                NUF=getNUF(c(Value1,Value2,Value3,Value4),medianValue),
                NUF2=getNUF(c(Value1,Value2,Value3,Value4),avgValue)) %>% ungroup()

# df.or.rt.new.s.kept <- inner_join(df.or.rt.new.s.kept,df.rating.new.s,by='participant')

df.s.combined.or <- rbind(df.or.rt.12.kept %>% select(minKept,valueKept,NUFKept,NChosen,NUF,NUFKept2,NUF2,conflict,meanValue,medianValue,valueDiff,trialN,firstRT,acc,participant) %>% mutate(study='old'),
                          df.or.rt.new.s.kept %>% filter(firstRT<15) %>% select(minKept,valueKept,NUFKept,NChosen,NUF,NUFKept2,NUF2,conflict,meanValue,medianValue,valueDiff,trialN,firstRT,acc,participant) %>% mutate(study='new')) %>% ungroup() %>%
  dplyr::mutate(scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledTrialNum=scale(trialN),
         scaledFirstRT=scale(firstRT),
         scaledConflict=scale(conflict),
         scaledNUF=scale(NUF),
         scaledNUF2=scale(NUF2),
         study=factor(study))

contrasts(df.s.combined.or$acc)<-contr.sum
contrasts(df.s.combined.or$study)<-contr.sum
df.or.rt.3.kept <- inner_join(df.or.rt.3,
                               df.rating.3.summary,by='participant') %>% 
  rowwise() %>%
  dplyr::mutate(valueKept = getMeanUnChosen(c(Value1,Value2,Value3,Value4),
                                          c(Order1,Order2,Order3,Order4)),
                minKept=getMinUnChosen(c(Value1,Value2,Value3,Value4),
                                     c(Order1,Order2,Order3,Order4)),
                NUFKept=getNUFUnChosen(c(Value1,Value2,Value3,Value4),
                                     c(Order1,Order2,Order3,Order4),
                                     medianValue),
                NUFKept2=getNUFUnChosen(c(Value1,Value2,Value3,Value4),
                                     c(Order1,Order2,Order3,Order4),
                                     avgValue),
                NUF=getNUF(c(Value1,Value2,Value3,Value4),medianValue),
                NUF2=getNUF(c(Value1,Value2,Value3,Value4),avgValue)) %>% ungroup()

df.or.rt.new.d.kept <- inner_join(df.or.rt.new.d,df.rating.new.d,by='participant') %>% rowwise() %>%
  dplyr::mutate(valueKept = getMeanUnChosen(c(Value1,Value2,Value3,Value4),
                                          c(Order1,Order2,Order3,Order4)),
                minKept=getMinUnChosen(c(Value1,Value2,Value3,Value4),
                                     c(Order1,Order2,Order3,Order4)),
                NUFKept=getNUFUnChosen(c(Value1,Value2,Value3,Value4),
                                     c(Order1,Order2,Order3,Order4),
                                     medianValue),
                NUFKept2=getNUFUnChosen(c(Value1,Value2,Value3,Value4),
                                     c(Order1,Order2,Order3,Order4),
                                     avgValue),
                NUF=getNUF(c(Value1,Value2,Value3,Value4),medianValue),
                NUF2=getNUF(c(Value1,Value2,Value3,Value4),avgValue)) %>% ungroup()

df.d.combined.or <- rbind(df.or.rt.3.kept %>% select(minKept,valueKept,NUFKept,NChosen,NUFKept2,NUF,NUF2,conflict,meanValue,medianValue,valueDiff,trialN,firstRT,acc,participant) %>% mutate(study='old'),
                          df.or.rt.new.d.kept %>% filter(firstRT<15) %>% select(minKept,valueKept,NUFKept,NChosen,NUFKept2,NUF,NUF2,conflict,meanValue,medianValue,valueDiff,trialN,firstRT,acc,participant) %>% mutate(study='new')) %>% ungroup() %>%
  dplyr::mutate(scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledTrialNum=scale(trialN),
         scaledFirstRT=scale(firstRT),
         scaledConflict=scale(conflict),
         scaledNUF=scale(NUF),
         scaledNUF2=scale(NUF2),
         NRemain = 4 - NChosen,
         NRemain2 = if_else(NChosen<4,4 - NChosen,1),
         study=factor(study))

contrasts(df.d.combined.or$acc)<-contr.sum
contrasts(df.d.combined.or$study)<-contr.sum
model.N.s.combined.01 <- lmer(NChosen ~ study * (scaledConflict + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.s.combined.or,REML=F)
## boundary (singular) fit: see help('isSingular')
model.N.d.combined.01 <- lmer(NChosen ~ study * (scaledConflict + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.d.combined.or,REML=F)
## boundary (singular) fit: see help('isSingular')
model.NR.d.combined.01 <- lmer(NRemain ~ study * (scaledConflict + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.d.combined.or,REML=F)
## boundary (singular) fit: see help('isSingular')
polymv <- poly(df.s.combined.or$scaledMeanValue,2)

df.s.combined.or$mvL <-polymv[,1]
df.s.combined.or$mvQ <-polymv[,2]

model.N.s.combined.01.direct <- lmer(NChosen ~ study * (scaledConflict + mvL + mvQ + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + mvL + mvQ + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.s.combined.or,REML=F)
## boundary (singular) fit: see help('isSingular')
model.nuf.s.combined.ni.01.direct <- lmer(NUFKept2/NChosen ~ study * (scaledConflict + scaledNUF2 + mvL + mvQ + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + scaledNUF2 + mvL + mvQ + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.s.combined.or,REML=F)
## boundary (singular) fit: see help('isSingular')
model.nuf.s.combined.ni.01.poly <- lmer(NUFKept2/NChosen ~ study * (scaledConflict + scaledNUF2 + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + scaledNUF2 + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.s.combined.or,REML=F)
## boundary (singular) fit: see help('isSingular')
model.N.s.combined.01.poly <- lmer(NChosen ~ study * (scaledConflict + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.s.combined.or,REML=F)
## boundary (singular) fit: see help('isSingular')
polymv <- poly(df.d.combined.or$scaledMeanValue,2)

df.d.combined.or$mvL <-polymv[,1]
df.d.combined.or$mvQ <-polymv[,2]

model.N.d.combined.01.direct <- lmer(NChosen ~ study * (scaledConflict + mvL + mvQ + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + mvL + mvQ + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.d.combined.or,REML=F)
## boundary (singular) fit: see help('isSingular')
model.NR.d.combined.01.direct <- lmer(NRemain ~ study * (scaledConflict + mvL + mvQ + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + mvL + mvQ + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.d.combined.or,REML=F)
## boundary (singular) fit: see help('isSingular')
model.nuf.d.combined.ni.01.direct <- lmer(NUFKept2/NRemain2 ~ study * (scaledConflict + scaledNUF2 + mvL + mvQ + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + scaledNUF2 + mvL + mvQ + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.d.combined.or,REML=F)
## boundary (singular) fit: see help('isSingular')
model.nuf.d.combined.ni.01.poly <- lmer(NUFKept2/NRemain2 ~ study * (scaledConflict + scaledNUF2 + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + scaledNUF2 + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.d.combined.or,REML=F)
## boundary (singular) fit: see help('isSingular')
model.N.d.combined.01.poly <- lmer(NChosen ~ study * (scaledConflict + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.d.combined.or,REML=F)
## boundary (singular) fit: see help('isSingular')
df.all.combined.or.gr <- rbind(df.s.combined.or %>% mutate(NUFRatio=NUFKept2/NChosen,
                                                           NKept=NChosen) %>% select(NUFRatio,NUF2,NKept,conflict,meanValue,valueDiff,trialN,firstRT,acc,participant,scaledConflict,scaledMeanValue,scaledValueDiff,scaledFirstRT,scaledTrialNum,study,scaledNUF2) %>% mutate(action='s'),
                               df.d.combined.or %>% mutate(NUFRatio=NUFKept2/NRemain2,
                                                           NKept=NRemain) %>% 
select(NUFRatio,NUF2,NKept,conflict,meanValue,valueDiff,trialN,firstRT,acc,participant,scaledConflict,scaledMeanValue,scaledValueDiff,scaledFirstRT,scaledTrialNum,study,scaledNUF2) %>% mutate(action='r')) %>% mutate(action=factor(action)) %>%
  mutate(study=factor(study),
         scaledConflict=scale(conflict),
         scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledTrialNum=scale(trialN),
         scaledFirstRT=scale(firstRT),
         scaledNUF2=scale(NUF2))

contrasts(df.all.combined.or.gr$acc)<-contr.sum
contrasts(df.all.combined.or.gr$study)<-contr.sum
contrasts(df.all.combined.or.gr$action)<-contr.sum

model.N.all.combined<- lmer(NKept ~ study * action * (scaledConflict + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.all.combined.or.gr)
## boundary (singular) fit: see help('isSingular')
model.nuf.all.combined.ni<- lmer(NUFRatio ~ study * action * (scaledConflict + scaledNUF2 + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc) + (1 + scaledConflict + scaledNUF2 + poly(scaledMeanValue,2) + scaledTrialNum + scaledValueDiff + scaledFirstRT + acc|participant),data=df.all.combined.or.gr)
## boundary (singular) fit: see help('isSingular')
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
kbl(car::Anova(model.N.s.combined.01.poly,type="III"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
Chisq Df Pr(>Chisq)
(Intercept) 1766.405 1 0.000
study 0.040 1 0.841
scaledConflict 4.103 1 0.043
poly(scaledMeanValue, 2) 391.693 2 0.000
scaledTrialNum 2.295 1 0.130
scaledValueDiff 20.285 1 0.000
scaledFirstRT 60.274 1 0.000
acc 17.957 1 0.000
study:scaledConflict 0.074 1 0.785
study:poly(scaledMeanValue, 2) 3.370 2 0.185
study:scaledTrialNum 0.682 1 0.409
study:scaledValueDiff 0.000 1 0.984
study:scaledFirstRT 32.757 1 0.000
study:acc 0.686 1 0.408
kbl(car::Anova(model.N.d.combined.01.poly,type="III"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
Chisq Df Pr(>Chisq)
(Intercept) 3134.507 1 0.000
study 5.506 1 0.019
scaledConflict 30.216 1 0.000
poly(scaledMeanValue, 2) 395.738 2 0.000
scaledTrialNum 0.576 1 0.448
scaledValueDiff 8.585 1 0.003
scaledFirstRT 182.101 1 0.000
acc 0.470 1 0.493
study:scaledConflict 1.397 1 0.237
study:poly(scaledMeanValue, 2) 2.413 2 0.299
study:scaledTrialNum 1.396 1 0.237
study:scaledValueDiff 0.079 1 0.778
study:scaledFirstRT 71.691 1 0.000
study:acc 25.813 1 0.000
kbl(car::Anova(model.nuf.s.combined.ni.01.poly,type="III"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
Chisq Df Pr(>Chisq)
(Intercept) 2892.356 1 0.000
study 2.639 1 0.104
scaledConflict 7.240 1 0.007
scaledNUF2 4263.954 1 0.000
poly(scaledMeanValue, 2) 22.267 2 0.000
scaledTrialNum 4.818 1 0.028
scaledValueDiff 274.512 1 0.000
scaledFirstRT 2.402 1 0.121
acc 109.606 1 0.000
study:scaledConflict 1.386 1 0.239
study:scaledNUF2 0.001 1 0.971
study:poly(scaledMeanValue, 2) 5.415 2 0.067
study:scaledTrialNum 4.986 1 0.026
study:scaledValueDiff 6.652 1 0.010
study:scaledFirstRT 1.251 1 0.263
study:acc 0.604 1 0.437
kbl(car::Anova(model.nuf.d.combined.ni.01.poly,type="III"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
Chisq Df Pr(>Chisq)
(Intercept) 1628.943 1 0.000
study 4.915 1 0.027
scaledConflict 10.977 1 0.001
scaledNUF2 3311.947 1 0.000
poly(scaledMeanValue, 2) 107.874 2 0.000
scaledTrialNum 2.801 1 0.094
scaledValueDiff 293.749 1 0.000
scaledFirstRT 23.018 1 0.000
acc 7.891 1 0.005
study:scaledConflict 1.201 1 0.273
study:scaledNUF2 0.518 1 0.472
study:poly(scaledMeanValue, 2) 0.471 2 0.790
study:scaledTrialNum 2.264 1 0.132
study:scaledValueDiff 0.471 1 0.493
study:scaledFirstRT 14.911 1 0.000
study:acc 126.357 1 0.000
kbl(car::Anova(model.N.all.combined,type="III"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
Chisq Df Pr(>Chisq)
(Intercept) 4825.819 1 0.000
study 2.941 1 0.086
action 17.878 1 0.000
scaledConflict 29.611 1 0.000
poly(scaledMeanValue, 2) 731.735 2 0.000
scaledTrialNum 3.205 1 0.073
scaledValueDiff 4.165 1 0.041
scaledFirstRT 0.267 1 0.605
acc 7.609 1 0.006
study:action 0.279 1 0.597
study:scaledConflict 0.945 1 0.331
study:poly(scaledMeanValue, 2) 5.091 2 0.078
study:scaledTrialNum 2.073 1 0.150
study:scaledValueDiff 0.035 1 0.852
study:scaledFirstRT 0.936 1 0.333
study:acc 8.352 1 0.004
action:scaledConflict 4.146 1 0.042
action:poly(scaledMeanValue, 2) 67.886 2 0.000
action:scaledTrialNum 3.118 1 0.077
action:scaledValueDiff 48.953 1 0.000
action:scaledFirstRT 200.528 1 0.000
action:acc 12.224 1 0.000
study:action:scaledConflict 0.265 1 0.607
study:action:poly(scaledMeanValue, 2) 1.294 2 0.524
study:action:scaledTrialNum 0.580 1 0.446
study:action:scaledValueDiff 0.409 1 0.522
study:action:scaledFirstRT 106.539 1 0.000
study:action:acc 15.027 1 0.000
kbl(car::Anova(model.nuf.all.combined.ni,type="III"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
Chisq Df Pr(>Chisq)
(Intercept) 3642.579 1 0.000
study 3.490 1 0.062
action 21.406 1 0.000
scaledConflict 20.623 1 0.000
scaledNUF2 5237.155 1 0.000
poly(scaledMeanValue, 2) 55.682 2 0.000
scaledTrialNum 8.076 1 0.004
scaledValueDiff 565.062 1 0.000
scaledFirstRT 21.381 1 0.000
acc 41.776 1 0.000
study:action 4.672 1 0.031
study:scaledConflict 0.114 1 0.735
study:scaledNUF2 1.661 1 0.197
study:poly(scaledMeanValue, 2) 2.197 2 0.333
study:scaledTrialNum 5.862 1 0.015
study:scaledValueDiff 7.731 1 0.005
study:scaledFirstRT 2.630 1 0.105
study:acc 37.392 1 0.000
action:scaledConflict 1.143 1 0.285
action:scaledNUF2 2.372 1 0.124
action:poly(scaledMeanValue, 2) 140.836 2 0.000
action:scaledTrialNum 0.041 1 0.839
action:scaledValueDiff 11.899 1 0.001
action:scaledFirstRT 6.212 1 0.013
action:acc 105.693 1 0.000
study:action:scaledConflict 2.427 1 0.119
study:action:scaledNUF2 0.449 1 0.503
study:action:poly(scaledMeanValue, 2) 0.064 2 0.969
study:action:scaledTrialNum 0.027 1 0.870
study:action:scaledValueDiff 3.954 1 0.047
study:action:scaledFirstRT 13.022 1 0.000
study:action:acc 55.284 1 0.000
tab_model(model.N.s.combined.01,model.N.d.combined.01,model.NR.d.combined.01,model.N.all.combined,digits=3)
  NChosen NChosen NRemain NKept
Predictors Estimates CI p Estimates CI p Estimates CI p Estimates CI p
(Intercept) 2.277 2.170 – 2.383 <0.001 1.873 1.807 – 1.938 <0.001 2.127 2.061 – 2.193 <0.001 2.200 2.138 – 2.262 <0.001
study1 0.011 -0.095 – 0.117 0.841 -0.078 -0.144 – -0.013 0.019 0.078 0.013 – 0.144 0.019 0.054 -0.008 – 0.116 0.086
scaledConflict 0.023 0.001 – 0.045 0.043 -0.051 -0.069 – -0.033 <0.001 0.050 0.032 – 0.068 <0.001 0.037 0.024 – 0.051 <0.001
scaledMeanValue [1st
degree]
49.107 44.243 – 53.971 <0.001 -47.806 -52.565 – -43.047 <0.001 47.837 43.077 – 52.597 <0.001 68.247 63.302 – 73.193 <0.001
scaledMeanValue [2nd
degree]
6.175 3.087 – 9.264 <0.001 10.830 8.515 – 13.144 <0.001 -10.819 -13.124 – -8.514 <0.001 -2.905 -5.691 – -0.118 0.041
scaledTrialNum 0.021 -0.006 – 0.048 0.130 -0.008 -0.028 – 0.012 0.448 0.008 -0.012 – 0.028 0.446 0.015 -0.001 – 0.032 0.073
scaledValueDiff -0.056 -0.081 – -0.032 <0.001 -0.027 -0.045 – -0.009 0.003 0.027 0.009 – 0.045 0.003 -0.015 -0.030 – -0.001 0.041
scaledFirstRT -0.118 -0.148 – -0.088 <0.001 -0.129 -0.147 – -0.110 <0.001 0.129 0.110 – 0.147 <0.001 0.005 -0.013 – 0.022 0.605
acc1 0.038 0.020 – 0.055 <0.001 0.006 -0.011 – 0.022 0.493 -0.006 -0.022 – 0.011 0.493 0.017 0.005 – 0.029 0.006
study1 × scaledConflict 0.003 -0.019 – 0.025 0.785 -0.011 -0.029 – 0.007 0.237 0.011 -0.007 – 0.029 0.235 0.007 -0.007 – 0.020 0.331
study1 × scaledMeanValue
[1st degree]
4.174 -0.690 – 9.039 0.093 -3.752 -8.511 – 1.007 0.122 3.757 -1.003 – 8.517 0.122 5.324 0.378 – 10.269 0.035
study1 × scaledMeanValue
[2nd degree]
-0.647 -3.735 – 2.442 0.682 0.778 -1.536 – 3.092 0.510 -0.778 -3.082 – 1.527 0.508 -1.382 -4.169 – 1.405 0.331
study1 × scaledTrialNum 0.011 -0.016 – 0.039 0.409 -0.012 -0.032 – 0.008 0.237 0.012 -0.008 – 0.032 0.237 0.012 -0.004 – 0.029 0.150
study1 × scaledValueDiff 0.000 -0.024 – 0.025 0.984 0.003 -0.015 – 0.021 0.778 -0.003 -0.021 – 0.015 0.783 -0.001 -0.016 – 0.013 0.852
study1 × scaledFirstRT 0.087 0.057 – 0.117 <0.001 0.081 0.062 – 0.099 <0.001 -0.081 -0.099 – -0.062 <0.001 0.009 -0.009 – 0.026 0.333
study1 × acc1 0.007 -0.010 – 0.025 0.408 0.042 0.026 – 0.059 <0.001 -0.042 -0.058 – -0.026 <0.001 -0.018 -0.030 – -0.006 0.004
action1 -0.096 -0.140 – -0.051 <0.001
study1 × action1 0.012 -0.032 – 0.056 0.597
action1 × scaledConflict 0.014 0.001 – 0.027 0.042
action1 × scaledMeanValue
[1st degree]
-4.280 -8.455 – -0.106 0.044
action1 × scaledMeanValue
[2nd degree]
-10.010 -12.541 – -7.479 <0.001
action1 × scaledTrialNum -0.014 -0.030 – 0.002 0.077
action1 × scaledValueDiff 0.049 0.035 – 0.062 <0.001
action1 × scaledFirstRT 0.119 0.103 – 0.136 <0.001
action1 × acc1 -0.021 -0.033 – -0.009 <0.001
(study1 × action1) ×
scaledConflict
0.003 -0.010 – 0.017 0.607
(study1 × action1) ×
scaledMeanValue [1st
degree]
-1.291 -5.466 – 2.883 0.544
(study1 × action1) ×
scaledMeanValue [2nd
degree]
1.315 -1.217 – 3.846 0.309
(study1 × action1) ×
scaledTrialNum
-0.006 -0.022 – 0.010 0.446
(study1 × action1) ×
scaledValueDiff
0.004 -0.009 – 0.018 0.522
(study1 × action1) ×
scaledFirstRT
-0.087 -0.103 – -0.070 <0.001
study1 × action1 × acc1 -0.023 -0.035 – -0.012 <0.001
Random Effects
σ2 0.40 0.36 0.36 0.38
τ00 0.39 participant 0.15 participant 0.15 participant 0.26 participant
τ11 0.00 participant.scaledConflict 0.00 participant.scaledConflict 0.00 participant.scaledConflict 0.00 participant.scaledConflict
710.22 participant.poly(scaledMeanValue, 2)1 729.52 participant.poly(scaledMeanValue, 2)1 730.20 participant.poly(scaledMeanValue, 2)1 1481.47 participant.poly(scaledMeanValue, 2)1
201.89 participant.poly(scaledMeanValue, 2)2 78.14 participant.poly(scaledMeanValue, 2)2 76.60 participant.poly(scaledMeanValue, 2)2 286.16 participant.poly(scaledMeanValue, 2)2
0.02 participant.scaledTrialNum 0.01 participant.scaledTrialNum 0.01 participant.scaledTrialNum 0.01 participant.scaledTrialNum
0.01 participant.scaledValueDiff 0.00 participant.scaledValueDiff 0.00 participant.scaledValueDiff 0.00 participant.scaledValueDiff
0.02 participant.scaledFirstRT 0.00 participant.scaledFirstRT 0.00 participant.scaledFirstRT 0.01 participant.scaledFirstRT
0.00 participant.acc1 0.00 participant.acc1 0.00 participant.acc1 0.00 participant.acc1
ρ01 -0.02 -0.74 -0.80 -0.37
0.19 -0.35 -0.35 -0.04
-0.67 -0.45 -0.46 -0.69
0.25 0.36 0.36 0.29
-0.73 -0.92 -0.92 -0.93
-0.29 -0.73 -0.73 -0.43
-0.20 0.34 0.41 -0.18
ICC   0.42    
N 141 participant 159 participant 159 participant 294 participant
Observations 8587 9349 9349 17936
Marginal R2 / Conditional R2 0.467 / NA 0.350 / 0.624 0.482 / NA 0.478 / NA
tab_model(model.nuf.s.combined.ni.01.direct,model.nuf.d.combined.ni.01.direct,digits=3)
  NUFKept2/NChosen NUFKept2/NRemain2
Predictors Estimates CI p Estimates CI p
(Intercept) 0.285 0.275 – 0.296 <0.001 0.322 0.306 – 0.338 <0.001
study1 -0.009 -0.019 – 0.002 0.104 -0.018 -0.033 – -0.002 0.027
scaledConflict 0.007 0.002 – 0.013 0.007 0.011 0.004 – 0.017 0.001
scaledNUF2 0.342 0.332 – 0.352 <0.001 0.352 0.340 – 0.364 <0.001
mvL -0.498 -1.286 – 0.289 0.215 9.395 7.518 – 11.273 <0.001
mvQ 1.442 0.839 – 2.045 <0.001 -4.331 -5.290 – -3.372 <0.001
scaledTrialNum 0.005 0.001 – 0.010 0.028 0.005 -0.001 – 0.012 0.094
scaledValueDiff -0.082 -0.092 – -0.073 <0.001 -0.056 -0.062 – -0.050 <0.001
scaledFirstRT 0.005 -0.001 – 0.010 0.121 0.014 0.008 – 0.020 <0.001
acc1 0.048 0.039 – 0.057 <0.001 -0.010 -0.018 – -0.003 0.005
study1 × scaledConflict -0.003 -0.009 – 0.002 0.239 0.003 -0.003 – 0.010 0.273
study1 × scaledNUF2 -0.000 -0.010 – 0.010 0.971 0.004 -0.008 – 0.016 0.472
study1 × mvL -0.728 -1.516 – 0.060 0.070 -0.524 -2.402 – 1.353 0.584
study1 × mvQ 0.530 -0.073 – 1.133 0.085 0.326 -0.633 – 1.286 0.505
study1 × scaledTrialNum 0.005 0.001 – 0.010 0.026 0.005 -0.001 – 0.011 0.132
study1 × scaledValueDiff -0.013 -0.023 – -0.003 0.010 -0.002 -0.009 – 0.004 0.493
study1 × scaledFirstRT 0.003 -0.002 – 0.009 0.263 -0.012 -0.017 – -0.006 <0.001
study1 × acc1 -0.004 -0.013 – 0.005 0.437 0.041 0.034 – 0.049 <0.001
Random Effects
σ2 0.03 0.06
τ00 0.00 participant 0.01 participant
τ11 0.00 participant.scaledConflict 0.00 participant.scaledConflict
0.00 participant.scaledNUF2 0.00 participant.scaledNUF2
1.05 participant.mvL 72.46 participant.mvL
4.85 participant.mvQ 17.54 participant.mvQ
0.00 participant.scaledTrialNum 0.00 participant.scaledTrialNum
0.00 participant.scaledValueDiff 0.00 participant.scaledValueDiff
0.00 participant.scaledFirstRT 0.00 participant.scaledFirstRT
0.00 participant.acc1 0.00 participant.acc1
ρ01 -0.34 -0.97
0.56 0.57
0.98 -0.74
-0.72 0.62
0.08 0.31
0.72 -0.13
-0.40 -0.75
-0.39 0.02
N 141 participant 159 participant
Observations 8587 9349
Marginal R2 / Conditional R2 0.799 / NA 0.600 / NA
tab_model(model.nuf.all.combined.ni,digits=3)
  NUFRatio
Predictors Estimates CI p
(Intercept) 0.303 0.293 – 0.313 <0.001
study1 -0.009 -0.019 – 0.000 0.062
action1 -0.020 -0.028 – -0.011 <0.001
scaledConflict 0.009 0.005 – 0.013 <0.001
scaledNUF2 0.344 0.335 – 0.354 <0.001
scaledMeanValue [1st
degree]
5.409 3.987 – 6.830 <0.001
scaledMeanValue [2nd
degree]
-1.875 -2.714 – -1.037 <0.001
scaledTrialNum 0.006 0.002 – 0.010 0.004
scaledValueDiff -0.069 -0.074 – -0.063 <0.001
scaledFirstRT 0.010 0.006 – 0.014 <0.001
acc1 0.020 0.014 – 0.026 <0.001
study1 × action1 -0.009 -0.018 – -0.001 0.031
study1 × scaledConflict 0.001 -0.003 – 0.005 0.735
study1 × scaledNUF2 0.006 -0.003 – 0.015 0.197
study1 × scaledMeanValue
[1st degree]
-0.736 -2.158 – 0.685 0.310
study1 × scaledMeanValue
[2nd degree]
0.625 -0.213 – 1.463 0.144
study1 × scaledTrialNum 0.005 0.001 – 0.009 0.015
study1 × scaledValueDiff -0.008 -0.014 – -0.002 0.005
study1 × scaledFirstRT -0.003 -0.008 – 0.001 0.105
study1 × acc1 0.019 0.013 – 0.025 <0.001
action1 × scaledConflict 0.002 -0.002 – 0.006 0.285
action1 × scaledNUF2 0.007 -0.002 – 0.015 0.124
action1 × scaledMeanValue
[1st degree]
7.191 5.852 – 8.530 <0.001
action1 × scaledMeanValue
[2nd degree]
-4.118 -4.916 – -3.319 <0.001
action1 × scaledTrialNum -0.000 -0.004 – 0.004 0.839
action1 × scaledValueDiff 0.010 0.004 – 0.015 0.001
action1 × scaledFirstRT 0.005 0.001 – 0.009 0.013
action1 × acc1 -0.030 -0.035 – -0.024 <0.001
(study1 × action1) ×
scaledConflict
0.003 -0.001 – 0.007 0.119
(study1 × action1) ×
scaledNUF2
-0.003 -0.012 – 0.006 0.503
(study1 × action1) ×
scaledMeanValue [1st
degree]
-0.100 -1.439 – 1.239 0.883
(study1 × action1) ×
scaledMeanValue [2nd
degree]
-0.041 -0.840 – 0.758 0.920
(study1 × action1) ×
scaledTrialNum
-0.000 -0.004 – 0.004 0.870
(study1 × action1) ×
scaledValueDiff
0.006 0.000 – 0.011 0.047
(study1 × action1) ×
scaledFirstRT
-0.007 -0.011 – -0.003 <0.001
study1 × action1 × acc1 0.021 0.016 – 0.027 <0.001
Random Effects
σ2 0.04
τ00 participant 0.01
τ11 participant.scaledConflict 0.00
τ11 participant.scaledNUF2 0.00
τ11 participant.poly(scaledMeanValue, 2)1 58.67
τ11 participant.poly(scaledMeanValue, 2)2 22.53
τ11 participant.scaledTrialNum 0.00
τ11 participant.scaledValueDiff 0.00
τ11 participant.scaledFirstRT 0.00
τ11 participant.acc1 0.00
ρ01 -0.65
0.64
-0.46
0.29
0.28
0.25
-0.75
-0.19
N participant 294
Observations 17936
Marginal R2 / Conditional R2 0.700 / NA
eff_vd.n.s.all <- Effect(c("scaledValueDiff"),
                   model.N.s.combined.01,
                   xlevels=list(scaledValueDiff=seq(min(quantile(df.s.combined.or$scaledValueDiff,0.025),
                                                        quantile(df.d.combined.or$scaledValueDiff,0.025)),
                                                    max(quantile(df.s.combined.or$scaledValueDiff,0.975),
                                                        quantile(df.d.combined.or$scaledValueDiff,0.975)),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledConflict, scaledTrialNum, scaledValueDiff, scaledFirstRT,
## scaledMeanValue are one-column matrices that were converted to vectors
IA.vd.N.s.all <- as.data.frame(eff_vd.n.s.all) %>% mutate(study='Selection')


eff_vd.n.d.all <- Effect(c("scaledValueDiff"),
                   model.N.d.combined.01,
                   xlevels=list(scaledValueDiff=seq(min(quantile(df.s.combined.or$scaledValueDiff,0.025),
                                                        quantile(df.d.combined.or$scaledValueDiff,0.025)),
                                                    max(quantile(df.s.combined.or$scaledValueDiff,0.975),
                                                        quantile(df.d.combined.or$scaledValueDiff,0.975)),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledConflict, scaledTrialNum, scaledValueDiff, scaledFirstRT,
## scaledMeanValue are one-column matrices that were converted to vectors
IA.vd.N.d.all <- as.data.frame(eff_vd.n.d.all) %>% mutate(study='Removal')

IA.vd.N.all <- rbind(IA.vd.N.s.all,IA.vd.N.d.all)
p.eff.vd.N.all<-ggplot(data=IA.vd.N.all, aes(x=scaledValueDiff, y=fit, group=study)) +
  geom_line(size=0.5,aes(color=study))+theme_bw(12) +
  geom_ribbon(data=IA.vd.N.all, aes(x=scaledValueDiff, max = upper, min = lower,fill=study),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("N Chosen") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        axis.title.y.right = element_text(color = '#AA0000', size=6)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#AA0000','#222222')) + 
  scale_color_manual("",values=c('#AA0000','#222222')) + 
  coord_cartesian(ylim=c(1.5,2.5)) +   scale_y_continuous(
    name = "N Chosen",
    breaks = c(1.5,2.5),
    sec.axis = sec_axis(~.*1, name="N Removed",breaks=c(1.5,2.5))
  )
p.eff.vd.N.all

eff_mv.n.s.all <- Effect(c("scaledMeanValue"),
                   model.N.s.combined.01,
                   xlevels=list(scaledMeanValue=seq(min(quantile(df.s.combined.or$scaledMeanValue,0.025),
                                                        quantile(df.d.combined.or$scaledMeanValue,0.025)),
                                                    max(quantile(df.s.combined.or$scaledMeanValue,0.975),
                                                        quantile(df.d.combined.or$scaledMeanValue,0.975)),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledConflict, scaledTrialNum, scaledValueDiff, scaledFirstRT,
## scaledMeanValue are one-column matrices that were converted to vectors
IA.mv.N.s.all <- as.data.frame(eff_mv.n.s.all) %>% mutate(study='Selection')


eff_mv.n.d.all <- Effect(c("scaledMeanValue"),
                   model.N.d.combined.01,
                   xlevels=list(scaledMeanValue=seq(min(quantile(df.s.combined.or$scaledMeanValue,0.025),
                                                        quantile(df.d.combined.or$scaledMeanValue,0.025)),
                                                    max(quantile(df.s.combined.or$scaledMeanValue,0.975),
                                                        quantile(df.d.combined.or$scaledMeanValue,0.975)),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledConflict, scaledTrialNum, scaledValueDiff, scaledFirstRT,
## scaledMeanValue are one-column matrices that were converted to vectors
IA.mv.N.d.all <- as.data.frame(eff_mv.n.d.all) %>% mutate(study='Removal')

IA.mv.N.all <- rbind(IA.mv.N.s.all,IA.mv.N.d.all)
p.eff.mv.N.all<-ggplot(data=IA.mv.N.all, aes(x=scaledMeanValue, y=fit, group=study)) +
  geom_line(size=0.5,aes(color=study))+theme_bw(12) +
  geom_ribbon(data=IA.mv.N.all, aes(x=scaledMeanValue, max = upper, min = lower,fill=study),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall Value\n(z-scored)") + ylab("N Chosen") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        axis.title.y.right = element_text(color = '#AA0000', size=6)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#AA0000','#222222')) + 
  scale_color_manual("",values=c('#AA0000','#222222')) + 
  coord_cartesian(ylim=c(1,4)) +   scale_y_continuous(
    name = "N Chosen",
    breaks = c(1,4),
    sec.axis = sec_axis(~.*1, name="N Removed",breaks=c(1,4))
  )
p.eff.mv.N.all

eff_mv.nc.s <- Effect(c("scaledConflict"),
                   model.N.s.combined.01.direct,
                   xlevels=list(scaledConflict=seq(min(quantile(df.s.combined.or$scaledConflict,0.025),
                                                        quantile(df.d.combined.or$scaledConflict,0.025)),
                                                    max(quantile(df.s.combined.or$scaledConflict,0.975),
                                                        quantile(df.d.combined.or$scaledConflict,0.975)),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledConflict, scaledTrialNum, scaledValueDiff, scaledFirstRT are
## one-column matrices that were converted to vectors
IA.mv.nc.s <- as.data.frame(eff_mv.nc.s) %>% mutate(study='Selection')


eff_mv.nc.d <- Effect(c("scaledConflict"),
                   model.NR.d.combined.01.direct,
                   xlevels=list(scaledConflict=seq(min(quantile(df.s.combined.or$scaledConflict,0.025),
                                                        quantile(df.d.combined.or$scaledConflict,0.025)),
                                                    max(quantile(df.s.combined.or$scaledConflict,0.975),
                                                        quantile(df.d.combined.or$scaledConflict,0.975)),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledConflict, scaledTrialNum, scaledValueDiff, scaledFirstRT are
## one-column matrices that were converted to vectors
IA.mv.nc.d <- as.data.frame(eff_mv.nc.d) %>% mutate(study='Removal')

IA.mv.nc.t <- rbind(IA.mv.nc.s,IA.mv.nc.d) %>% mutate(study=relevel(factor(study),ref = 'Selection'))


test<-ggplot(data=IA.mv.nc.t, aes(x=scaledConflict, y=fit, group=study)) +
  geom_line(size=0.5,aes(color=study))+theme_bw(12) +
  geom_ribbon(data=IA.mv.nc.t, aes(x=scaledConflict, max = upper, min = lower,fill=study),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Conflict\n(z-scored)") + ylab("N Kept") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position = 'none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#222222','#AA0000')) + 
  scale_color_manual("",values=c('#222222','#AA0000')) + 
  coord_cartesian(ylim=c(2,2.5)) + scale_y_continuous(breaks = c(2,2.5))
test

eff_mv.nc.s <- Effect(c("scaledConflict"),
                   model.nuf.s.combined.ni.01.direct,
                   xlevels=list(scaledConflict=seq(min(quantile(df.s.combined.or$scaledConflict,0.025),
                                                        quantile(df.d.combined.or$scaledConflict,0.025)),
                                                    max(quantile(df.s.combined.or$scaledConflict,0.975),
                                                        quantile(df.d.combined.or$scaledConflict,0.975)),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledConflict, scaledNUF2, scaledTrialNum, scaledValueDiff,
## scaledFirstRT are one-column matrices that were converted to vectors
IA.mv.nc.s <- as.data.frame(eff_mv.nc.s) %>% mutate(study='Selection')


eff_mv.nc.d <- Effect(c("scaledConflict"),
                   model.nuf.d.combined.ni.01.direct,
                   xlevels=list(scaledConflict=seq(min(quantile(df.s.combined.or$scaledConflict,0.025),
                                                        quantile(df.d.combined.or$scaledConflict,0.025)),
                                                    max(quantile(df.s.combined.or$scaledConflict,0.975),
                                                        quantile(df.d.combined.or$scaledConflict,0.975)),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledConflict, scaledNUF2, scaledTrialNum, scaledValueDiff,
## scaledFirstRT are one-column matrices that were converted to vectors
IA.mv.nc.d <- as.data.frame(eff_mv.nc.d) %>% mutate(study='Removal')

IA.mv.nc.t <- rbind(IA.mv.nc.s,IA.mv.nc.d) %>% mutate(study=relevel(factor(study),ref = 'Selection'))


test2<-ggplot(data=IA.mv.nc.t, aes(x=scaledConflict, y=fit, group=study)) +
  geom_line(size=0.5,aes(color=study))+theme_bw(12) +
  geom_ribbon(data=IA.mv.nc.t, aes(x=scaledConflict, max = upper, min = lower,fill=study),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Conflict\n(z-scored)") + ylab("P(Suboptimal)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position = 'none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#222222','#AA0000')) + 
  scale_color_manual("",values=c('#222222','#AA0000')) + 
  coord_cartesian(ylim=c(.2,.4)) + scale_y_continuous(breaks = c(.2,.4))
test2

df.value.12 <- gather(df.total.rt.12 %>% select(participant,trialN,Value1:Value4,meanValue,valueDiff,catChoiceCondition),
       'position','value',Value1:Value4)

df.order.12 <- gather(df.total.rt.12 %>% select(participant,trialN,Order1:Order4),
       'position','order',Order1:Order4)

df.value.12$order <- df.order.12$order

df.order.value.12 <- inner_join(df.value.12,rbind(df.rating.1.summary,df.rating.2.summary),by='participant')

df.value.ns <- gather(df.total.rt.new.s %>% select(participant,trialN,Value1:Value4,meanValue,valueDiff,catChoiceCondition),
       'position','value',Value1:Value4)

df.order.ns <- gather(df.total.rt.new.s %>% select(participant,trialN,Order1:Order4),
       'position','order',Order1:Order4)

df.value.ns$order <- df.order.ns$order

df.order.value.ns <- inner_join(df.value.ns,df.rating.new.s %>% select(participant,medianValue,avgValue),by='participant')

df.order.value.s <- rbind(df.order.value.12 %>% mutate(study='1'),df.order.value.ns %>% mutate(study='2')) %>% 
  filter(catChoiceCondition=='OR') %>%
  mutate(isOpt=factor(value>avgValue),
         isChosen=factor(order>0),
         order=factor(order),
         scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledValue=scale(value),
         scaledAvgValue=scale(avgValue),
         scaledDevValue=scale(value-avgValue),
         study=factor(study))
contrasts(df.order.value.s$study)<-contr.sum


model.order.s <- glmer(isChosen ~ scaledMeanValue + scaledDevValue + (1 + scaledMeanValue + scaledDevValue |participant) + (1|study),data=df.order.value.s,
                     family=binomial())

summary(model.order.s)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: isChosen ~ scaledMeanValue + scaledDevValue + (1 + scaledMeanValue +  
##     scaledDevValue | participant) + (1 | study)
##    Data: df.order.value.s
## 
##      AIC      BIC   logLik deviance df.resid 
##  34332.9  34417.3 -17156.4  34312.9    34370 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -9.9147 -0.6174  0.1875  0.5924  7.7932 
## 
## Random effects:
##  Groups      Name            Variance Std.Dev. Corr       
##  participant (Intercept)     3.2990   1.8163              
##              scaledMeanValue 0.1667   0.4082    0.22      
##              scaledDevValue  0.8870   0.9418   -0.19 -0.80
##  study       (Intercept)     0.1752   0.4186              
## Number of obs: 34380, groups:  participant, 141; study, 2
## 
## Fixed effects:
##                 Estimate Std. Error z value Pr(>|z|)    
## (Intercept)      0.46587    0.33491   1.391    0.164    
## scaledMeanValue -0.80118    0.04671 -17.153   <2e-16 ***
## scaledDevValue   2.11210    0.08787  24.036   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) scldMV
## scaledMenVl  0.063       
## scaledDevVl -0.069 -0.756
df.value.3 <- gather(df.total.rt.3 %>% select(participant,trialN,Value1:Value4,meanValue,valueDiff,catChoiceCondition),
       'position','value',Value1:Value4)

df.order.3 <- gather(df.total.rt.3 %>% select(participant,trialN,Order1:Order4),
       'position','order',Order1:Order4)

df.value.3$order <- df.order.3$order

df.order.value.3 <- inner_join(df.value.3,df.rating.3.summary,by='participant')

df.value.newd <- gather(df.total.rt.new.d %>% select(participant,trialN,Value1:Value4,meanValue,valueDiff,catChoiceCondition),
       'position','value',Value1:Value4)

df.order.newd <- gather(df.total.rt.new.d %>% select(participant,trialN,Order1:Order4),
       'position','order',Order1:Order4)

df.value.newd$order <- df.order.newd$order

df.order.value.nd <- inner_join(df.value.newd,df.rating.new.d  %>% select(participant,medianValue,avgValue),by='participant')

df.order.value.d <- rbind(df.order.value.3 %>% mutate(study='1'),df.order.value.nd %>% mutate(study='2')) %>% 
  filter(catChoiceCondition=='OR') %>%
  mutate(isOpt=factor(value>avgValue),
         isChosen=factor(order>0),
         scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledValue=scale(value),
         scaledAvgValue=scale(avgValue),
         scaledDevValue=scale(value-avgValue),
         study=factor(study))
contrasts(df.order.value.d$study)<-contr.sum


model.order.d <- glmer(isChosen ~ scaledMeanValue + scaledDevValue + (1 + scaledMeanValue + scaledDevValue |participant) + (1|study),data=df.order.value.d,
                     family=binomial())

summary(model.order.d)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: isChosen ~ scaledMeanValue + scaledDevValue + (1 + scaledMeanValue +  
##     scaledDevValue | participant) + (1 | study)
##    Data: df.order.value.d
## 
##      AIC      BIC   logLik deviance df.resid 
##  41748.1  41833.4 -20864.0  41728.1    37410 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -8.8007 -0.7063 -0.3027  0.7419  7.9274 
## 
## Random effects:
##  Groups      Name            Variance Std.Dev. Corr       
##  participant (Intercept)     0.6408   0.8005              
##              scaledMeanValue 0.1910   0.4370   -0.24      
##              scaledDevValue  0.7355   0.8576   -0.01 -0.90
##  study       (Intercept)     0.0118   0.1086              
## Number of obs: 37420, groups:  participant, 159; study, 2
## 
## Fixed effects:
##                 Estimate Std. Error z value Pr(>|z|)    
## (Intercept)     -0.19868    0.10243   -1.94   0.0524 .  
## scaledMeanValue  0.91615    0.04577   20.02   <2e-16 ***
## scaledDevValue  -1.75188    0.07390  -23.71   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) scldMV
## scaledMenVl -0.132       
## scaledDevVl  0.001 -0.836
rawDevValue <- seq(-5,5,0.1)

newscaledDevValue <- scale(rawDevValue,center = mean(df.order.value.d$value-df.order.value.d$avgValue),
                           scale = sd(df.order.value.d$value-df.order.value.d$avgValue))

df.effect.value.d <- data.frame(Effect(model.order.d,focal.predictors = c('scaledDevValue'),xlevels=list(scaledDevValue=newscaledDevValue)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledDevValue are one-column matrices that were
## converted to vectors
df.effect.value.d$rawx <- rawDevValue

df.effect.value.d$study <- 'd'

newscaledDevValue <- scale(rawDevValue,center = mean(df.order.value.s$value-df.order.value.s$avgValue),
                           scale = sd(df.order.value.s$value-df.order.value.s$avgValue))

df.effect.value.s <- data.frame(Effect(model.order.s,focal.predictors = c('scaledDevValue'),xlevels=list(scaledDevValue=newscaledDevValue)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledDevValue are one-column matrices that were
## converted to vectors
df.effect.value.s$rawx <- rawDevValue

df.effect.value.s$study <- 's'

df.effect.value <- rbind(df.effect.value.s,df.effect.value.d) %>% mutate(study=factor(study))

contrasts(df.effect.value$study) <- contr.sum
p.eff.vtr.N.all<-ggplot(data=df.effect.value, aes(x=rawx, y=fit, group=study)) +
  geom_line(size=0.5,aes(color=study))+theme_bw(12) +
  geom_ribbon(data=df.effect.value, aes(x=rawx, max = upper, min = lower,fill=study),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Item Value - Average") + ylab("P(Chosen)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        axis.title.y.right = element_text(color = '#AA0000', size=6)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#AA0000','#222222')) + 
  scale_color_manual("",values=c('#AA0000','#222222')) + 
  coord_cartesian(ylim=c(0,1)) +   scale_y_continuous(
    breaks = c(0,0.5,1),
    sec.axis = sec_axis(~.*1, name="P(Removed)",breaks=c(0,0.5,1))
  ) + geom_vline(xintercept = 0,size=0.2) + geom_hline(yintercept = 0.5,size=0.2)
p.eff.vtr.N.all

lay <- rbind(c(1,2,NA),c(1,2,3),c(4,5,3),c(4,5,NA))

plots <- list(p.eff.mv.N.all,p.eff.vd.N.all,p.eff.vtr.N.all,test,test2)
grobs <- list()
widths <- list()
heights <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths
    heights[[i]] <- grobs[[i]]$heights
}

maxwidth <- do.call(grid::unit.pmax, widths)
maxheight <- do.call(grid::unit.pmax,heights)

for (i in 1:length(grobs)){
     grobs[[i]]$heights <- as.list(maxheight)
     grobs[[i]]$widths <- as.list(maxwidth)
}

p<-grid.arrange(grobs = grobs, layout_matrix = lay,widths=unit(c(3.6,3.6,3.6), c("cm", "cm")),heights=unit(c(1.5,1.5,1.5,1.5),c('cm')))

ggsave(filename = '../Figures/Figure9_V3.pdf',p,units = 'cm',width = 18,height = 10)
df.rating.ddl <- read.csv('../Data/Study4/Study4_2.csv')

df.total.ddl <- read.csv('../Data/Study4/Study4_1.csv') %>%
  mutate(catChoiceCondition=relevel(factor(duration),ref='60'),
         isBestFirst=firstValue==bestValue,
         scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledTrialNum=scale(trialN))

df.total.rt.ddl <- df.total.ddl %>% 
  mutate(catChoiceCondition=relevel(factor(duration),ref='60'),
         rr=firstValue/firstRT) %>% filter(firstRT>0.1,firstRT<15) %>%
  mutate(scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledTrialNum=scale(trialN))

contrasts(df.total.ddl$catChoiceCondition)<-contr.sdif
contrasts(df.total.rt.ddl$catChoiceCondition)<-contr.sdif
df.total.rt.ddl$scaledRT<-scale(log10(df.total.rt.ddl$firstRT))
df.total.rt.ddl$acc<-as.factor(df.total.rt.ddl$isBestFirst)
contrasts(df.total.rt.ddl$acc)<-contr.sum
df.total.rt.ddl$rr <- df.total.rt.ddl$firstValue/df.total.rt.ddl$firstRT

model.rr <- lmerTest::lmer(rr ~ catChoiceCondition * ( scaledMeanValue + scaledValueDiff) + scaledTrialNum + (1 + catChoiceCondition * ( scaledMeanValue + scaledValueDiff) + scaledTrialNum|participant),data=df.total.rt.ddl)
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 1 negative eigenvalue: -3.1e+01
model.RT <- lmerTest::lmer(firstRT ~ catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.ddl)
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 3 negative eigenvalues: -3.6e-01
## -9.5e-01 -2.3e+03
model.acc <- glmer(isBestFirst ~ catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.ddl,family = binomial)
## boundary (singular) fit: see help('isSingular')
model.acc.dummy <- lmer(isBestFirst ~ catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.ddl)
## boundary (singular) fit: see help('isSingular')
# model.rr.ddl <- lmerTest::lmer(rr ~ catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * scaledMeanValue + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.ddl)

model.rating <- lmerTest::lmer(conflict ~ catChoiceCondition * poly(scaledMeanValue,2) + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * poly(scaledMeanValue,2) + scaledValueDiff|participant),data=df.total.ddl)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.00865799 (tol = 0.002, component 1)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model is nearly unidentifiable: large eigenvalue ratio
##  - Rescale variables?
## Warning: Model failed to converge with 1 negative eigenvalue: -4.6e+00
library(kableExtra)

kbl(car::Anova(model.RT,type="III"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
Chisq Df Pr(>Chisq)
(Intercept) 991.732 1 0
catChoiceCondition 106.936 1 0
scaledMeanValue 274.291 1 0
scaledValueDiff 83.856 1 0
scaledTrialNum 51.006 1 0
catChoiceCondition:scaledMeanValue 48.488 1 0
catChoiceCondition:scaledValueDiff 39.197 1 0
kbl(car::Anova(model.acc,type="III"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
Chisq Df Pr(>Chisq)
(Intercept) 28.115 1 0.000
catChoiceCondition 9.336 1 0.002
scaledMeanValue 0.082 1 0.775
scaledValueDiff 287.903 1 0.000
scaledTrialNum 0.542 1 0.462
catChoiceCondition:scaledMeanValue 0.253 1 0.615
catChoiceCondition:scaledValueDiff 0.877 1 0.349
kbl(car::Anova(model.rating,type="III"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
Chisq Df Pr(>Chisq)
(Intercept) 1876.556 1 0.000
catChoiceCondition 0.645 1 0.422
poly(scaledMeanValue, 2) 46.932 2 0.000
scaledValueDiff 15.930 1 0.000
scaledTrialNum 1.419 1 0.234
catChoiceCondition:poly(scaledMeanValue, 2) 0.826 2 0.662
catChoiceCondition:scaledValueDiff 5.341 1 0.021
model.RT.coeff <- lmerTest::lmer(firstRT ~ catChoiceCondition / scaledMeanValue + catChoiceCondition / scaledValueDiff + scaledTrialNum + 
                     (1 + catChoiceCondition / scaledMeanValue + catChoiceCondition / scaledValueDiff + scaledTrialNum|participant), 
                   data=df.total.rt.ddl)
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 1 negative eigenvalue: -2.5e+01
coeff.mat.RT <- coef(summary(model.RT.coeff))
coeff.mat.RT.ov <- data.frame(coeff.mat.RT[c('catChoiceCondition3:scaledMeanValue',
                                      'catChoiceCondition60:scaledMeanValue'),
                                    c('Estimate','Std. Error')])
coeff.mat.RT.ov$catChoiceCondition <- c('OR','XOR')
colnames(coeff.mat.RT.ov) <- c('beta_OV','se_OV','catChoiceCondition')
coeff.mat.RT.vd <- data.frame(coeff.mat.RT[c('catChoiceCondition3:scaledValueDiff',
                                      'catChoiceCondition60:scaledValueDiff')
                                    ,c('Estimate','Std. Error')])
coeff.mat.RT.vd$catChoiceCondition <- c('OR','XOR')
colnames(coeff.mat.RT.vd) <- c('beta_VD','se_VD','catChoiceCondition')

coeff.mat.RT <- inner_join(data.frame(coeff.mat.RT.ov),
                             data.frame(coeff.mat.RT.vd),by='catChoiceCondition') %>% mutate(study='Study DDL')
rownames(coeff.mat.RT) <- NULL

coeff.mat.RT <- rbind(coeff.mat.RT)

#coeff.mat.RT$catChoiceCondition <- rownames(coeff.mat.RT)

5.0.1 Extract coefficents in DDL study

model.acc.coeff <- glmer(isBestFirst ~ catChoiceCondition / scaledMeanValue + catChoiceCondition / scaledValueDiff + scaledTrialNum + 
                     (1 + catChoiceCondition / scaledMeanValue + catChoiceCondition / scaledValueDiff + scaledTrialNum|participant),
                     data=df.total.rt.ddl,family=binomial)
## Warning in (function (fn, par, lower = rep.int(-Inf, n), upper = rep.int(Inf, :
## failure to converge in 10000 evaluations
## Warning in optwrap(optimizer, devfun, start, rho$lower, control = control, :
## convergence code 4 from Nelder_Mead: failure to converge in 10000 evaluations
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## unable to evaluate scaled gradient
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge: degenerate Hessian with 1 negative eigenvalues
coeff.mat.Acc <- coef(summary(model.acc.coeff))
coeff.mat.Acc.ov <- data.frame(coeff.mat.Acc[c('catChoiceCondition3:scaledMeanValue',
                                      'catChoiceCondition60:scaledMeanValue'),
                                    c('Estimate','Std. Error')])
coeff.mat.Acc.ov$catChoiceCondition <- c('OR','XOR')
colnames(coeff.mat.Acc.ov) <- c('beta_OV','se_OV','catChoiceCondition')
coeff.mat.Acc.vd <- data.frame(coeff.mat.Acc[c('catChoiceCondition3:scaledValueDiff',
                                      'catChoiceCondition60:scaledValueDiff')
                                    ,c('Estimate','Std. Error')])
coeff.mat.Acc.vd$catChoiceCondition <- c('OR','XOR')
colnames(coeff.mat.Acc.vd) <- c('beta_VD','se_VD','catChoiceCondition')

coeff.mat.Acc <- inner_join(data.frame(coeff.mat.Acc.ov),
                             data.frame(coeff.mat.Acc.vd),by='catChoiceCondition') %>% mutate(study='Study DDL')
rownames(coeff.mat.Acc) <- NULL

coeff.mat.Acc <- rbind(coeff.mat.Acc)

coeff.mat.RT.total <- rbind(coeff.mat.RT,coeff.mat.RT.12) %>% mutate(color=c('DDL','NULL','OR','NULL'))


coeff.mat.Acc.total <- rbind(coeff.mat.Acc,coeff.mat.Acc.12) %>% mutate(color=c('DDL','NULL','OR','NULL'))
coeff.mat.RT.total$catChoiceCondition <- relevel(factor(coeff.mat.RT.total$catChoiceCondition),'XOR')
p.rt.mv.coeff.summary.14 <- ggplot(coeff.mat.RT.total %>% filter(study %in% c('Study 12','Study DDL')),aes(x = study,y=beta_OV,group=catChoiceCondition,color=color)) + geom_point(position = position_dodge(0.5),size=1) + geom_errorbar(position=position_dodge(0.5),aes(ymin=beta_OV-se_OV,ymax=beta_OV+se_OV,color=color),width=0.1) + theme_bw(12) + theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",0.2),
        axis.ticks=element_line(colour='black',0.2)) + 
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + ylab('Effect of OV') + xlab('') + scale_x_discrete(labels=c('Inclusivity','Urgency')) + scale_color_manual(values=c('#B02000','#0673C3',"#00B024"))  + scale_y_continuous(limits = c(-0.5,0.05),breaks=c(-0.5,0)) + geom_hline(yintercept = 0,linetype="dashed",size=0.2)

p.rt.mv.coeff.summary.14

coeff.mat.RT.total$catChoiceCondition <- relevel(factor(coeff.mat.RT.total$catChoiceCondition),'XOR')
p.rt.vd.coeff.summary.14 <- ggplot(coeff.mat.RT.total %>% filter(study %in% c('Study 12','Study DDL')),aes(x = study,y=beta_VD,group=catChoiceCondition,color=color)) + geom_point(position = position_dodge(0.5),size=1) + geom_errorbar(position=position_dodge(0.5),aes(ymin=beta_VD-se_VD,ymax=beta_VD+se_VD,color=color),width=0.1) + theme_bw(12) + theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",0.2),
        axis.ticks=element_line(colour='black',0.2)) + 
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + ylab('Effect of RV') + xlab('') + scale_x_discrete(labels=c('Inclusivity','Urgency')) + scale_color_manual(values=c('#B02000','#0673C3',"#00B024"))  + scale_y_continuous(limits = c(-0.5,0.05),breaks=c(-0.5,0)) + geom_hline(yintercept = 0,linetype="dashed",size=0.2)

p.rt.vd.coeff.summary.14

model.rating.coeff <- lmer(conflict ~ catChoiceCondition / poly(scaledMeanValue,2) + catChoiceCondition / scaledValueDiff + scaledTrialNum + 
                     (1 + catChoiceCondition / poly(scaledMeanValue,2) + catChoiceCondition / scaledValueDiff + scaledTrialNum|participant),
                     data=df.total.ddl)
## boundary (singular) fit: see help('isSingular')
model.rating.coeff.12 <- lmer(conflict ~ catChoiceCondition / poly(scaledMeanValue,2) + catChoiceCondition / scaledValueDiff + scaledTrialNum + 
                     (1 + catChoiceCondition / poly(scaledMeanValue,2) + catChoiceCondition / scaledValueDiff + scaledTrialNum|participant),
                     data=df.total.valid.12)
## boundary (singular) fit: see help('isSingular')
coeff.mat.rating <- coef(summary(model.rating.coeff))
coeff.mat.rating.ov <- data.frame(coeff.mat.rating[c('catChoiceCondition3:poly(scaledMeanValue, 2)1',
                                      'catChoiceCondition60:poly(scaledMeanValue, 2)1'),
                                    c('Estimate','Std. Error')])
coeff.mat.rating.ov$catChoiceCondition <- c('OR','XOR')
colnames(coeff.mat.rating.ov) <- c('beta_OV','se_OV','catChoiceCondition')
coeff.mat.rating.vd <- data.frame(coeff.mat.rating[c('catChoiceCondition3:scaledValueDiff',
                                      'catChoiceCondition60:scaledValueDiff')
                                    ,c('Estimate','Std. Error')])
coeff.mat.rating.vd$catChoiceCondition <- c('OR','XOR')
colnames(coeff.mat.rating.vd) <- c('beta_VD','se_VD','catChoiceCondition')

coeff.mat.rating <- inner_join(data.frame(coeff.mat.rating.ov),
                             data.frame(coeff.mat.rating.vd),by='catChoiceCondition') %>% mutate(study='Study DDL')
rownames(coeff.mat.rating) <- NULL

coeff.mat.rating <- rbind(coeff.mat.rating)

#coeff.mat.RT$catChoiceCondition <- rownames(coeff.mat.RT)
coeff.mat.rating.12 <- coef(summary(model.rating.coeff.12))
coeff.mat.rating.12.ov <- data.frame(coeff.mat.rating.12[c('catChoiceConditionOR:poly(scaledMeanValue, 2)1',
                                      'catChoiceConditionXOR:poly(scaledMeanValue, 2)1'),
                                    c('Estimate','Std. Error')])
coeff.mat.rating.12.ov$catChoiceCondition <- c('OR','XOR')
colnames(coeff.mat.rating.12.ov) <- c('beta_OV','se_OV','catChoiceCondition')
coeff.mat.rating.12.vd <- data.frame(coeff.mat.rating.12[c('catChoiceConditionOR:scaledValueDiff',
                                      'catChoiceConditionXOR:scaledValueDiff')
                                    ,c('Estimate','Std. Error')])
coeff.mat.rating.12.vd$catChoiceCondition <- c('OR','XOR')
colnames(coeff.mat.rating.12.vd) <- c('beta_VD','se_VD','catChoiceCondition')

coeff.mat.rating.12 <- inner_join(data.frame(coeff.mat.rating.12.ov),
                             data.frame(coeff.mat.rating.12.vd),by='catChoiceCondition') %>% mutate(study='Study 12')
rownames(coeff.mat.rating.12) <- NULL

coeff.mat.rating.12 <- rbind(coeff.mat.rating.12)

#coeff.mat.RT$catChoiceCondition <- rownames(coeff.mat.RT)

coeff.mat.rating.total <- rbind(coeff.mat.rating,coeff.mat.rating.12) %>% mutate(color=c('DDL','NULL','OR','NULL'))
coeff.mat.rating.total$catChoiceCondition <- relevel(factor(coeff.mat.rating.total$catChoiceCondition),'XOR')
p.cfl.mv.coeff.summary.14 <-ggplot(coeff.mat.rating.total %>% filter(study %in% c('Study 12','Study DDL')),aes(x = study,y=beta_OV,group=catChoiceCondition,color=color)) + geom_point(position = position_dodge(0.5),size=1) + geom_errorbar(position=position_dodge(0.5),aes(ymin=beta_OV-se_OV,ymax=beta_OV+se_OV,color=color),width=0.1) + theme_bw(12) + theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",0.2),
        axis.ticks=element_line(colour='black',0.2)) + 
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + ylab('Effect of OV\n(1st Order)') + xlab('') + scale_x_discrete(labels=c('Inclusivity','Urgency')) + scale_color_manual(values=c('#B02000','#0673C3',"#00B024")) + scale_y_continuous(limits = c(-10,40),breaks=c(0,40))+geom_hline(yintercept = 0,linetype="dashed",size=0.2)

p.cfl.mv.coeff.summary.14

coeff.mat.rating.total$catChoiceCondition <- relevel(factor(coeff.mat.rating.total$catChoiceCondition),'XOR')
p.cfl.vd.coeff.summary.14 <-ggplot(coeff.mat.rating.total %>% filter(study %in% c('Study 12','Study DDL')),aes(x = study,y=beta_VD,group=catChoiceCondition,color=color)) + geom_point(position = position_dodge(0.5),size=1) + geom_errorbar(position=position_dodge(0.5),aes(ymin=beta_VD-se_VD,ymax=beta_VD+se_VD,color=color),width=0.1) + theme_bw(12) + theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",0.2),
        axis.ticks=element_line(colour='black',0.2)) + 
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + ylab('Effect of RV') + xlab('') + scale_x_discrete(labels=c('Inclusivity','Urgency')) + scale_color_manual(values=c('#B02000','#0673C3',"#00B024")) + scale_y_continuous(limits = c(-0.15,0.025),breaks=c(-0.15,0))+geom_hline(yintercept = 0,linetype="dashed",size=0.2)

p.cfl.vd.coeff.summary.14

lay <- rbind(c(1,2),c(3,4))

plots <- list(p.rt.mv.coeff.summary.14,p.rt.vd.coeff.summary.14,
              p.cfl.mv.coeff.summary.14,p.cfl.vd.coeff.summary.14)

grobs <- list()
widths <- list()
heights <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths
    heights[[i]] <- grobs[[i]]$heights
    
}

maxwidth <- do.call(grid::unit.pmax, widths)
maxheight <- do.call(grid::unit.pmax,heights)

for (i in 1:length(grobs)){
     grobs[[i]]$heights <- as.list(maxheight)
     grobs[[i]]$widths <- as.list(maxwidth)
}

p<-grid.arrange(grobs = grobs, layout_matrix = lay,widths=unit(c(3.5,3.5), c("cm", "cm")),heights=unit(c(3.5,3.5),c('cm','cm')))

ggsave(filename = '../Figures/Figure8_V4.pdf',p,units = 'cm',width = 15,height = 15)
poly.mv <- poly(df.total.ddl$scaledMeanValue,2)
df.total.ddl$mvL <- poly.mv[,1]
df.total.ddl$mvQ <- poly.mv[,2]

model.rating.direct <- lmerTest::lmer(conflict ~ catChoiceCondition * (mvL + mvQ) + catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * (mvL + mvQ) + catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.ddl)
## boundary (singular) fit: see help('isSingular')
eff_mv.cfl.ddl <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.rating,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.ddl$scaledMeanValue,0.025),
                                                    quantile(df.total.ddl$scaledMeanValue,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledValueDiff, scaledTrialNum, scaledMeanValue are one-column
## matrices that were converted to vectors
IA.mv.cfl.ddl <- as.data.frame(eff_mv.cfl.ddl)

IA.mv.cfl.ddl$catChoiceCondition <- relevel(IA.mv.cfl.ddl$catChoiceCondition,ref = '60')

p.eff.mv.cfl.ddl<-ggplot(data=IA.mv.cfl.ddl, aes(x=scaledMeanValue, y=fit,group=catChoiceCondition)) + 
  geom_line(size=0.5,aes(color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.cfl.ddl, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall Value\n(z-scored)") + ylab("Conflict") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6),strip.text.y = element_blank()) + 
  scale_fill_manual("",values=c('#0673C3','#B00024')) + 
  scale_color_manual("",values=c('#0673C3','#B00024')) + 
  coord_cartesian(ylim=c(1.5,3.5)) + scale_y_continuous(breaks = c(2,3))

p.eff.mv.cfl.ddl

eff_vd.cfl.ddl <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.rating,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.ddl$scaledValueDiff,0.025),
                                                    quantile(df.total.ddl$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledValueDiff, scaledTrialNum, scaledMeanValue are one-column
## matrices that were converted to vectors
IA.vd.cfl.ddl <- as.data.frame(eff_vd.cfl.ddl)

IA.vd.cfl.ddl$catChoiceCondition <- relevel(IA.vd.cfl.ddl$catChoiceCondition,ref = '60')

p.eff.vd.cfl.ddl<-ggplot(data=IA.vd.cfl.ddl, aes(x=scaledValueDiff, y=fit,group=catChoiceCondition)) + 
  geom_line(size=0.5,aes(color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.cfl.ddl, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("Conflict") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6),strip.text.y = element_blank()) + 
  scale_fill_manual("",values=c('#0673C3','#B00024')) + 
  scale_color_manual("",values=c('#0673C3','#B00024')) + 
  coord_cartesian(ylim=c(1.5,3.5)) + scale_y_continuous(breaks = c(2,3))

p.eff.vd.cfl.ddl

marginalConflictVDEffect <- function(model,x) {
  
  coeffs.mv.1 <- summary(model)$coeff[,'Estimate']
  
  eff <- coeffs.mv.1['catChoiceCondition3-60'] + 
    coeffs.mv.1['catChoiceCondition3-60:scaledValueDiff']*x
  
  cov.mat <- vcov(model)
  
  eff.ci <-  1.96 * sqrt(cov.mat[2,2] + x^2 * cov.mat[9,9] +
                                 2 * x * cov.mat[2,9])
  
  eff.df<-data.frame(x=x,eff=eff,ci=eff.ci)
  
  return(eff.df)
}
new.vd.1 <- seq(quantile(df.total.ddl$scaledValueDiff,0.025),
                quantile(df.total.ddl$scaledValueDiff,0.975),0.1)

eff.df.vd.ddl <- marginalConflictVDEffect(model.rating,new.vd.1) %>%
  dplyr::mutate(scaledValueDiff=x,
                catChoiceCondition='3 - 60',
                fit= eff,
                upper= eff+ci,
                lower= eff-ci,
                se=NA,
                study='Study 3')

p.eff.cc.int.ddl<-ggplot(data=eff.df.vd.ddl, aes(x=x, y=fit)) + 
  geom_line(size=0.5)+theme_bw(12) +
  geom_ribbon(data=eff.df.vd.ddl, aes(x=x, max = upper, min = lower),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab('Effect of Urgency') +
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        strip.text.y = element_blank()) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  scale_fill_manual("",values=c("#005555","#550055")) + scale_color_manual("",values=c("#005555","#550055")) + # ggtitle('Exclusive - Non-Exclusive')#  +
  coord_cartesian(ylim=c(-.15,0.5)) + scale_y_continuous(breaks = c(0,0.5))

p.eff.cc.int.ddl

coeff.rt <- t(fixef(model.RT)['catChoiceCondition3-60'])
df.ci <- confint(model.RT,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.rt <- df.ci['catChoiceCondition3-60',]
estimate.rt <- cbind(coeff.rt,t(ci.rt))
colnames(estimate.rt)<-c('coeff','lower','upper')

coeff.acc <- t(fixef(model.acc.dummy)['catChoiceCondition3-60'])
df.ci <- confint(model.acc.dummy,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.acc <- df.ci['catChoiceCondition3-60',]
estimate.acc <- cbind(coeff.acc,t(ci.acc))
colnames(estimate.acc)<-c('coeff','lower','upper')

coeff.rr <- t(fixef(model.rr)['catChoiceCondition3-60'])
df.ci <- confint(model.rr,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.rr <- df.ci['catChoiceCondition3-60',]
estimate.rr <- cbind(coeff.rr,t(ci.rr))
colnames(estimate.rr)<-c('coeff','lower','upper')

coeff.conf <- t(fixef(model.rating)['catChoiceCondition3-60'])
df.ci <- confint(model.rating,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.conf <- df.ci['catChoiceCondition3-60',]
estimate.conf <- cbind(coeff.conf,t(ci.conf))
colnames(estimate.conf)<-c('coeff','lower','upper')

estimate.all <- data.frame(rbind(estimate.rt,estimate.acc,estimate.rr,estimate.conf))
estimate.all$var <- c('RT','Acc','RR','Conflict')
p.diff.acc.ddl <- ggplot(estimate.all %>% filter(var %in% c('Acc')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Urgency")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("Acc"='P(Best First)')) + scale_y_continuous(limits = c(-0.1,0.01),breaks = c(-0.1,0))

p.diff.acc.ddl

p.diff.rt.ddl <- ggplot(estimate.all %>% filter(var %in% c('RT')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Urgency\n(sec)")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("RT"='RT')) + scale_y_continuous(limits = c(-2,0.2),breaks = c(-2,0))

p.diff.rt.ddl

p.diff.rr.ddl <- ggplot(estimate.all %>% filter(var %in% c('RR')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555',szie=0.2) + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Urgency\n(Unit Value/sec)")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("RR"='Reward Rate')) + scale_y_continuous(limits = c(-0.2,2),breaks = c(0,2))
## Warning in geom_hline(yintercept = 0, color = "#555555", szie = 0.2): Ignoring
## unknown parameters: `szie`
p.diff.rr.ddl

p.diff.conflict.ddl <- ggplot(estimate.all %>% filter(var %in% c('Conflict')), aes(x=var, y=coeff))  + geom_hline(yintercept=0,color='#555555') + 
  geom_point(stat="identity", position=position_dodge(0.6),size=0.5) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0.1,size=0.4,
                 position=position_dodge(.6))+labs(x="", y = "Effect of Urgency")+theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") +
  scale_x_discrete(labels=c("Conflict"='Conflict')) + scale_y_continuous(limits = c(-0.2,0.2),breaks = c(-0.2,0,0.2))
p.diff.conflict.ddl

eff_mv.RT.ddl <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.RT,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.rt.ddl$scaledMeanValue,0.025),
                                                    quantile(df.total.rt.ddl$scaledMeanValue,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.mv.RT.ddl <- as.data.frame(eff_mv.RT.ddl) %>% dplyr::mutate(study='Study 3')

p.eff.mv.rt.ddl<-ggplot(data=IA.mv.RT.ddl, aes(x=scaledMeanValue, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.RT.ddl, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall Value\n(z-scored)") + ylab("RT (sec)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#B00024')) + 
  scale_color_manual("",values=c('#0673C3','#B00024')) + 
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))

p.eff.mv.rt.ddl

eff_vd.RT.ddl <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.RT,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.rt.ddl$scaledValueDiff,0.025),
                                                    quantile(df.total.rt.ddl$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.vd.RT.ddl <- as.data.frame(eff_vd.RT.ddl) %>% dplyr::mutate(study='Study 3')

p.eff.vd.rt.ddl <-ggplot(data=IA.vd.RT.ddl, aes(x=scaledValueDiff, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.RT.ddl, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("RT (sec)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#B00024')) + 
  scale_color_manual("",values=c('#0673C3','#B00024')) + 
  coord_cartesian(ylim=c(1,4)) + scale_y_continuous(breaks = c(1,4))

p.eff.vd.rt.ddl

eff_mv.acc.ddl <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.acc,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.rt.ddl$scaledMeanValue,0.025),
                                                    quantile(df.total.rt.ddl$scaledMeanValue,0.972),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.mv.acc.ddl <- as.data.frame(eff_mv.acc.ddl) %>% dplyr::mutate(study='Study 3')

p.eff.mv.acc.ddl <-ggplot(data=IA.mv.acc.ddl, aes(x=scaledMeanValue, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.acc.ddl, aes(x=scaledMeanValue, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab("P(Best First)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#B00024')) + 
  scale_color_manual("",values=c('#0673C3','#B00024')) + 
  coord_cartesian(ylim=c(0.1,0.9)) + scale_y_continuous(breaks = c(0.1,0.9),labels=function(x) sprintf("%.1f", x))

p.eff.mv.acc.ddl

#ggsave('Study12_RT.pdf')
eff_vd.acc.ddl <- Effect(c("scaledValueDiff","catChoiceCondition"),
                   model.acc,
                   xlevels=list(scaledValueDiff=seq(quantile(df.total.rt.ddl$scaledValueDiff,0.025),
                                                    quantile(df.total.rt.ddl$scaledValueDiff,0.975),0.1)))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledMeanValue, scaledValueDiff, scaledTrialNum are one-column
## matrices that were converted to vectors
IA.vd.acc.ddl <- as.data.frame(eff_vd.acc.ddl) %>% dplyr::mutate(study='Study 3')

p.eff.vd.acc.ddl<-ggplot(data=IA.vd.acc.ddl, aes(x=scaledValueDiff, y=fit, group=catChoiceCondition)) +
  geom_line(size=0.5,aes(linetype=study,color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.vd.acc.ddl, aes(x=scaledValueDiff, max = upper, min = lower,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Relative Value\n(z-scored)") + ylab("P(Best First)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + 
  scale_fill_manual("",values=c('#0673C3','#B00024')) + 
  scale_color_manual("",values=c('#0673C3','#B00024')) + 
  coord_cartesian(ylim=c(0.1,0.9)) + scale_y_continuous(breaks = c(0.1,0.9),labels=function(x) sprintf("%.1f", x))

p.eff.vd.acc.ddl

#ggsave('Study12_RT.pdf')
lay <- rbind(c(1, 4, 4, 4, 7),
             c(2, 2, NA,3, 3),
             c(5, 5, NA,6, 6))

plots <- list(p.diff.rt.ddl,p.eff.mv.rt.ddl,p.eff.vd.rt.ddl,
              p.diff.acc.ddl,p.eff.mv.acc.ddl,p.eff.vd.acc.ddl,p.diff.rr.ddl)
grobs <- list()
widths <- list()
heights <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths
    heights[[i]] <- grobs[[i]]$heights
}

maxwidth <- do.call(grid::unit.pmax, widths)
maxheight <- do.call(grid::unit.pmax,heights)

for (i in c(2,3,5,6)){
     grobs[[i]]$widths <- as.list(maxwidth)
}

for (i in 1:length(grobs)){
     grobs[[i]]$heights <- as.list(maxheight)
}

widths <- list()

for (i in c(1,4,7)){
    widths[[i]] <- grobs[[i]]$widths
}

maxwidth <- do.call(grid::unit.pmax,widths)

for (i in c(1,4,7)){
     grobs[[i]]$widths <- as.list(maxwidth)
}

p<-grid.arrange(grobs = grobs, layout_matrix = lay,widths=unit(c(2.1,0.9,0.2,0.9,2.1), c("cm", "cm")),heights=unit(c(3,3,3),c('cm','cm')))

ggsave(filename = '../Figures/FigureS5_V2.pdf',p,units = 'cm',width = 10,height = 15)
lay <- rbind(c(1,NA,2,NA,3,NA,4))

plots <- list(p.diff.conflict.ddl,p.eff.mv.cfl.ddl,p.eff.vd.cfl.ddl,p.eff.cc.int.ddl)
grobs <- list()
widths <- list()
heights <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths
    heights[[i]] <- grobs[[i]]$heights
}

maxwidth <- do.call(grid::unit.pmax, widths)
maxheight <- do.call(grid::unit.pmax, heights)

for (i in 1:length(grobs)){
  grobs[[i]]$widths <- as.list(maxwidth)
  grobs[[i]]$heights <- as.list(maxheight)
}

p<-grid.arrange(grobs = grobs, layout_matrix = lay,widths=unit(c(2.1,0.1,2.7,0.1,2.7,0.1,2.7), c("cm", "cm")),heights=unit(c(3),c('cm','cm')))

ggsave(filename = '../Figures/FigureS6_V2.pdf',p,units = 'cm',width = 25,height = 12)
df.orxorg <- read.csv('../Data/Study5/Study5a/Study5a_1.csv')
df.orxorg.rating <- read.csv('../Data/Study5/Study5a/Study5a_2.csv')

# df.orxorg.rt <- read.csv('Study5a/resp1.csv')

df.orxori <- read.csv('../Data/Study5/Study5b/Study5b_1.csv')
df.orxorg.rating <- read.csv('../Data/Study5/Study5b/Study5b_2.csv')

# df.orxori.rt <- read.csv('Study5b/resp2.csv')
df.orxorgi <- rbind(df.orxorg %>% select(participant,firstRT,isBestFirst,meanValue,valueDiff,choiceCondition,trialNGlobal,conflict),
                    df.orxori %>% select(participant,firstRT,isBestFirst,meanValue,valueDiff,choiceCondition,trialNGlobal,conflict)) %>%
  mutate(scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledTrialNum=scale(trialNGlobal),
         catChoiceCondition=relevel(factor(choiceCondition,labels = c('OR','XOR')),ref = 'XOR'))

contrasts(df.orxorgi$catChoiceCondition) <- MASS::contr.sdif
df.orxorgi.rt <- rbind(df.orxorg %>% filter(firstRT>0.1) %>% select(participant,firstRT,isBestFirst,meanValue,valueDiff,choiceCondition,trialNGlobal,conflict),
                       df.orxori %>% filter(firstRT>0.1) %>% select(participant,firstRT,isBestFirst,meanValue,valueDiff,choiceCondition,trialNGlobal,conflict)) %>%
  mutate(scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledTrialNum=scale(trialNGlobal),
         catChoiceCondition=relevel(factor(choiceCondition,labels = c('OR','XOR')),ref = 'XOR'))

contrasts(df.orxorgi.rt$catChoiceCondition) <- MASS::contr.sdif
model.logRT.gi <- lmer(log10(firstRT) ~ catChoiceCondition * (scaledMeanValue + scaledValueDiff) + scaledTrialNum + (1 + catChoiceCondition * (scaledMeanValue + scaledValueDiff) + scaledTrialNum|participant),data=df.orxorgi.rt)
## boundary (singular) fit: see help('isSingular')
model.acc.gi <- glmer(isBestFirst ~ catChoiceCondition * (scaledMeanValue + scaledValueDiff) + scaledTrialNum + (1 + catChoiceCondition * (scaledMeanValue + scaledValueDiff) + scaledTrialNum|participant),data=df.orxorgi.rt,family = binomial())
## Warning in (function (fn, par, lower = rep.int(-Inf, n), upper = rep.int(Inf, :
## failure to converge in 10000 evaluations
## Warning in optwrap(optimizer, devfun, start, rho$lower, control = control, :
## convergence code 4 from Nelder_Mead: failure to converge in 10000 evaluations
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.0118834 (tol = 0.002, component 1)
model.conflict.gi <- lmer(conflict ~ catChoiceCondition * (poly(scaledMeanValue,2) + scaledValueDiff) + scaledTrialNum + (1 + catChoiceCondition * (poly(scaledMeanValue,2) + scaledValueDiff) + scaledTrialNum|participant),data=df.orxorgi)
## boundary (singular) fit: see help('isSingular')
df.orxori.total <- df.orxori %>% select(participant,firstRT,isBestFirst,meanValue,valueDiff,choiceCondition,trialNGlobal,conflict) %>%
  mutate(scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledTrialNum=scale(trialNGlobal),
         catChoiceCondition=relevel(factor(choiceCondition,labels = c('OR','XOR')),ref = 'XOR'))

contrasts(df.orxori.total$catChoiceCondition) <- MASS::contr.sdif
df.orxori.rt <- df.orxori.total %>% filter(firstRT>0.1) %>% select(participant,firstRT,isBestFirst,meanValue,valueDiff,choiceCondition,trialNGlobal,conflict) %>%
  mutate(scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff),
         scaledTrialNum=scale(trialNGlobal),
         catChoiceCondition=relevel(factor(choiceCondition,labels = c('OR','XOR')),ref = 'XOR'))

contrasts(df.orxori.rt$catChoiceCondition) <- MASS::contr.sdif
model.logRT.i <- lmer(log10(firstRT) ~ catChoiceCondition * (scaledMeanValue + scaledValueDiff) + scaledTrialNum + (1 + catChoiceCondition * (scaledMeanValue + scaledValueDiff) + scaledTrialNum|participant),data=df.orxori.rt)
## boundary (singular) fit: see help('isSingular')
model.acc.i <- glmer(isBestFirst ~ catChoiceCondition * (scaledMeanValue + scaledValueDiff) + scaledTrialNum + (1 + catChoiceCondition * (scaledMeanValue + scaledValueDiff) + scaledTrialNum|participant),data=df.orxori.rt,family = binomial())
## Warning in (function (fn, par, lower = rep.int(-Inf, n), upper = rep.int(Inf, :
## failure to converge in 10000 evaluations
## Warning in optwrap(optimizer, devfun, start, rho$lower, control = control, :
## convergence code 4 from Nelder_Mead: failure to converge in 10000 evaluations
## boundary (singular) fit: see help('isSingular')
model.conflict.i <- lmer(conflict ~ catChoiceCondition * (poly(scaledMeanValue,2) + scaledValueDiff) + scaledTrialNum + (1 + catChoiceCondition * (poly(scaledMeanValue,2) + scaledValueDiff) + scaledTrialNum|participant),data=df.orxori.total)
## boundary (singular) fit: see help('isSingular')
new.mv <- seq(quantile(df.orxorgi$scaledMeanValue,0.025),
              quantile(df.orxorgi$scaledMeanValue,0.975),0.1)

eff.df.mv.gi <- marginalConflictMVEffect(model.conflict.gi,df.orxorgi$scaledMeanValue,new.mv) %>%
  dplyr::mutate(scaledMeanValue=x,
                catChoiceCondition='XOR - OR',
                fit= eff,
                upper= eff+ci,
                lower= eff-ci,
                se=NA,
                study='Study 3')

p.eff.cc.int.gi<-ggplot(data=eff.df.mv.gi, aes(x=x, y=fit)) + 
  geom_line(size=0.5)+theme_bw(12) +
  geom_ribbon(data=eff.df.mv.gi, aes(x=x, max = upper, min = lower),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab('Effect of Inclusivity') +
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        strip.text.y = element_blank()) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  scale_fill_manual("",values=c("#005555","#550055")) + scale_color_manual("",values=c("#005555","#550055")) + # ggtitle('Exclusive - Non-Exclusive') +
  coord_cartesian(ylim=c(-1,0.3)) + scale_y_continuous(breaks = c(-1,0))

p.eff.cc.int.gi

ggsave(filename = '../Figures/FigureS1B.pdf',p.eff.cc.int.gi,units = 'cm',width = 3,height = 3)
new.mv <- seq(quantile(df.orxori.total$scaledMeanValue,0.025),
              quantile(df.orxori.total$scaledMeanValue,0.975),0.1)

eff.df.mv.i <- marginalConflictMVEffect(model.conflict.i,df.orxori.total$scaledMeanValue,new.mv) %>%
  dplyr::mutate(scaledMeanValue=x,
                catChoiceCondition='XOR - OR',
                fit= eff,
                upper= eff+ci,
                lower= eff-ci,
                se=NA,
                study='Study 3')

p.eff.cc.int.i<-ggplot(data=eff.df.mv.i, aes(x=x, y=fit)) + 
  geom_line(size=0.5)+theme_bw(12) +
  geom_ribbon(data=eff.df.mv.i, aes(x=x, max = upper, min = lower),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab('Effect of Inclusivity') +
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        strip.text.y = element_blank()) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + geom_hline(yintercept=0,color='#555555',size=0.2) + 
  scale_fill_manual("",values=c("#005555","#550055")) + scale_color_manual("",values=c("#005555","#550055")) + # ggtitle('Exclusive - Non-Exclusive') +
  coord_cartesian(ylim=c(-1,0.3)) + scale_y_continuous(breaks = c(-1,0))

p.eff.cc.int.i

ggsave(filename = '../Figures/FigureS2B.pdf',p.eff.cc.int.i,units = 'cm',width = 3,height = 3)
coeff.rt.ns <- fixef(model.logRT.gi)[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff')]
df.ci <- confint(model.logRT.gi,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.rt <- df.ci[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff'),]
estimate.rt.gi <- t(rbind(coeff.rt.ns,t(ci.rt)))
colnames(estimate.rt.gi)<-c('coeff','lower','upper')
rownames(estimate.rt.gi) <- NULL
estimate.rt.gi <- data.frame(estimate.rt.gi)
estimate.rt.gi$params <- c('Incl - Excl','(Incl - Excl) X OV','(Incl - Excl) X RV')
estimate.rt.gi$dv <- 'RT'
p.summary.gi.rt <- ggplot(estimate.rt.gi,aes(x=params,y=coeff)) + geom_hline(yintercept=0,color='#AAAAAA',size=0.2) + geom_point(position = position_dodge(0.6),size=0.5) + geom_errorbar(position = position_dodge(0.6),aes(ymin=lower,ymax=upper),width=0.2) + coord_flip() + theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") + scale_y_continuous(limits = c(-0.04,0.04),breaks = c(-0.04,0,0.04)) + xlab('') + ylab('') + scale_x_discrete(labels=c('Incl - Excl'='On intercept','(Incl - Excl) X OV'='On overall value effect','(Incl - Excl) X RV'='On relative value effect'))
p.summary.gi.rt

ggsave(filename = '../Figures/FigureS1A.pdf',p.summary.gi.rt,units = 'cm',width = 4.8,height = 3)
coeff.rt.ns <- fixef(model.logRT.i)[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff')]
df.ci <- confint(model.logRT.i,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.rt <- df.ci[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff'),]
estimate.rt.i <- t(rbind(coeff.rt.ns,t(ci.rt)))
colnames(estimate.rt.i)<-c('coeff','lower','upper')
rownames(estimate.rt.i) <- NULL
estimate.rt.i <- data.frame(estimate.rt.i)
estimate.rt.i$params <- c('Incl - Excl','(Incl - Excl) X OV','(Incl - Excl) X RV')
estimate.rt.i$dv <- 'RT'
p.summary.i.rt <- ggplot(estimate.rt.i,aes(x=params,y=coeff)) + geom_hline(yintercept=0,color='#AAAAAA',size=0.2) + geom_point(position = position_dodge(0.6),size=0.5) + geom_errorbar(position = position_dodge(0.6),aes(ymin=lower,ymax=upper),width=0.2) + coord_flip() + theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") + scale_y_continuous(limits = c(-0.04,0.04),breaks = c(-0.04,0,0.04)) + xlab('') + ylab('') + scale_x_discrete(labels=c('Incl - Excl'='On intercept','(Incl - Excl) X OV'='On overall value effect','(Incl - Excl) X RV'='On relative value effect'))
p.summary.i.rt

ggsave(filename = '../Figures/FigureS2A.pdf',p.summary.i.rt,units = 'cm',width = 4.8,height = 3)
library(kableExtra)
kbl(car::Anova(model.logRT.gi,type="3"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
Chisq Df Pr(>Chisq)
(Intercept) 960.803 1 0.000
catChoiceCondition 21.239 1 0.000
scaledMeanValue 109.712 1 0.000
scaledValueDiff 304.755 1 0.000
scaledTrialNum 167.979 1 0.000
catChoiceCondition:scaledMeanValue 13.097 1 0.000
catChoiceCondition:scaledValueDiff 0.639 1 0.424
kbl(car::Anova(model.acc.gi,type="3"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
Chisq Df Pr(>Chisq)
(Intercept) 36.082 1 0.000
catChoiceCondition 1.343 1 0.247
scaledMeanValue 3.413 1 0.065
scaledValueDiff 471.864 1 0.000
scaledTrialNum 1.768 1 0.184
catChoiceCondition:scaledMeanValue 0.251 1 0.617
catChoiceCondition:scaledValueDiff 1.690 1 0.194
kbl(car::Anova(model.conflict.gi,type="3"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
Chisq Df Pr(>Chisq)
(Intercept) 1295.542 1 0.000
catChoiceCondition 12.575 1 0.000
poly(scaledMeanValue, 2) 63.126 2 0.000
scaledValueDiff 16.882 1 0.000
scaledTrialNum 0.257 1 0.612
catChoiceCondition:poly(scaledMeanValue, 2) 11.170 2 0.004
catChoiceCondition:scaledValueDiff 0.780 1 0.377
library(kableExtra)
kbl(car::Anova(model.logRT.i,type="3"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
Chisq Df Pr(>Chisq)
(Intercept) 529.317 1 0.000
catChoiceCondition 6.040 1 0.014
scaledMeanValue 30.254 1 0.000
scaledValueDiff 155.705 1 0.000
scaledTrialNum 107.151 1 0.000
catChoiceCondition:scaledMeanValue 4.943 1 0.026
catChoiceCondition:scaledValueDiff 1.353 1 0.245
kbl(car::Anova(model.acc.i,type="3"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
Chisq Df Pr(>Chisq)
(Intercept) 19.270 1 0.000
catChoiceCondition 1.685 1 0.194
scaledMeanValue 1.674 1 0.196
scaledValueDiff 267.755 1 0.000
scaledTrialNum 2.027 1 0.155
catChoiceCondition:scaledMeanValue 0.026 1 0.873
catChoiceCondition:scaledValueDiff 0.357 1 0.550
kbl(car::Anova(model.conflict.i,type="3"),digits = 3) %>%
  kable_classic(full_width = F, html_font = "Cambria")
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
## Warning in printHypothesis(L, rhs, names(b)): one or more coefficients in the hypothesis include
##      arithmetic operators in their names;
##   the printed representation of the hypothesis will be omitted
Chisq Df Pr(>Chisq)
(Intercept) 697.799 1 0.000
catChoiceCondition 6.046 1 0.014
poly(scaledMeanValue, 2) 20.652 2 0.000
scaledValueDiff 9.372 1 0.002
scaledTrialNum 0.374 1 0.541
catChoiceCondition:poly(scaledMeanValue, 2) 5.797 2 0.055
catChoiceCondition:scaledValueDiff 0.070 1 0.791

6 Study 6

df.rating.6 <- read.csv('../Data/Study6/Study6_2.csv')

df.total.cfl.6 <- read.csv('../Data/Study6/Study6_1.csv') %>%
  mutate(catChoiceCondition=factor(choiceCondition,labels = c('OR','XOR'))) %>%
  mutate(isBestFirst=firstValue==bestValue) %>%
  mutate(scaledTrialNum=scale(trialNGlobal),
         scaledVarValue=scale(varValue),
         scaledValueDiff2=scale(bestValue-worstValue),
         scaledMeanValue=scale(meanValue),
         scaledValueDiff=scale(valueDiff))

df.total.rt.cfl.6 <- df.total.cfl.6 %>% filter(firstRT>0.1) %>%
  mutate(scaledTrialNum=scale(trialNGlobal),
         scaledMeanValue=scale(meanValue),
         scaledVarValue=scale(varValue),
         scaledValueDiff=scale(valueDiff),
         scaledRT=scale(firstRT),
         catAcc=factor(isBestFirst))
contrasts(df.total.rt.cfl.6$catAcc)<-contr.sum
df.total.rt.cfl.6$catChoiceCondition<-relevel(df.total.rt.cfl.6$catChoiceCondition,'XOR')
df.total.cfl.6$catChoiceCondition<-relevel(df.total.cfl.6$catChoiceCondition,'XOR')
contrasts(df.total.rt.cfl.6$catChoiceCondition)<-MASS::contr.sdif
contrasts(df.total.cfl.6$catChoiceCondition)<-MASS::contr.sdif
model.FRT.cfl <- lmerTest::lmer(log10(firstRT) ~ catChoiceCondition * (scaledMeanValue + scaledValueDiff) + scaledTrialNum + (1 + catChoiceCondition * (scaledMeanValue + scaledValueDiff) + scaledTrialNum|participant),data=df.total.rt.cfl.6,control=lmerControl(optCtrl=list(maxfun=50000) ))
## boundary (singular) fit: see help('isSingular')
model.acc.cfl <- glmer(isBestFirst ~ catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum + (1 + catChoiceCondition * scaledMeanValue +  catChoiceCondition * scaledValueDiff + scaledTrialNum|participant),data=df.total.rt.cfl.6,family = binomial)
## Warning in (function (fn, par, lower = rep.int(-Inf, n), upper = rep.int(Inf, :
## failure to converge in 10000 evaluations
## Warning in optwrap(optimizer, devfun, start, rho$lower, control = control, :
## convergence code 4 from Nelder_Mead: failure to converge in 10000 evaluations
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.0969178 (tol = 0.002, component 1)
model.rating.cfl <- lmerTest::lmer(conflict ~ catChoiceCondition * (poly(scaledMeanValue,2) + scaledValueDiff) + scaledTrialNum + (1 + catChoiceCondition * (poly(scaledMeanValue,2) + scaledValueDiff) + scaledTrialNum|participant),data=df.total.rt.cfl.6,control=lmerControl(optCtrl=list(maxfun=100000)))
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 2 negative eigenvalues: -1.5e-04
## -3.4e-03
coeff.rt.ns <- fixef(model.FRT.cfl)[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff')]
df.ci <- confint(model.FRT.cfl,method="Wald")
df.ci <- df.ci[!is.na(df.ci[,1]),]
ci.rt <- df.ci[c('catChoiceConditionOR-XOR','catChoiceConditionOR-XOR:scaledMeanValue','catChoiceConditionOR-XOR:scaledValueDiff'),]
estimate.rt.i <- t(rbind(coeff.rt.ns,t(ci.rt)))
colnames(estimate.rt.i)<-c('coeff','lower','upper')
rownames(estimate.rt.i) <- NULL
estimate.rt.i <- data.frame(estimate.rt.i)
estimate.rt.i$params <- c('Incl - Excl','(Incl - Excl) X OV','(Incl - Excl) X RV')
estimate.rt.i$dv <- 'RT'
p.summary.i.rt <- ggplot(estimate.rt.i,aes(x=params,y=coeff)) + geom_hline(yintercept=0,color='#AAAAAA',size=0.2) + geom_point(position = position_dodge(0.6),size=0.5) + geom_errorbar(position = position_dodge(0.6),aes(ymin=lower,ymax=upper),width=0.2) + coord_flip() + theme_bw(12) + 
  theme(panel.border = element_blank(),panel.grid.major = element_blank(),
        axis.title.x = element_text(margin = margin(t = 0, r = 0, b = 0, l = 0)),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2),
        text=element_text(size=6),legend.position="none") + scale_y_continuous(limits = c(-0.04,0.04),breaks = c(-0.04,0,0.04)) + xlab('') + ylab('') + scale_x_discrete(labels=c('Incl - Excl'='On intercept','(Incl - Excl) X OV'='On overall value effect','(Incl - Excl) X RV'='On relative value effect'))
p.summary.i.rt

ggsave(filename = '../Figures/FigureS2A.pdf',p.summary.i.rt,units = 'cm',width = 4.8,height = 3)
eff_mv.acc.3 <- Effect(c("scaledMeanValue","catChoiceCondition"),
                   model.rating.cfl,
                   xlevels=list(scaledMeanValue=seq(quantile(df.total.rt.cfl.6$scaledMeanValue,0.025),
                                                    quantile(df.total.rt.cfl.6$scaledMeanValue,0.975),0.1)
                                ))
## Warning in Analyze.model(focal.predictors, mod, xlevels, default.levels, : the
## predictors scaledValueDiff, scaledTrialNum, scaledMeanValue are one-column
## matrices that were converted to vectors
IA.mv.acc.3 <- as.data.frame(eff_mv.acc.3) %>% dplyr::mutate(study='Study 3')

p.eff.mv.acc.3 <-ggplot(data=IA.mv.acc.3, aes(x=scaledMeanValue, y=fit, group=catChoiceCondition)) + 
  geom_line(size=0.5,aes(color=catChoiceCondition))+theme_bw(12) +
  geom_ribbon(data=IA.mv.acc.3, aes(x=scaledMeanValue, max = lower, min = upper,fill=catChoiceCondition),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab("Conflict") + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(text = element_text(size=6),legend.position = 'none') + 
  scale_fill_manual("",values=c('#0673C3','#00B024')) + 
  scale_color_manual("",values=c('#0673C3','#00B024'))

p.eff.mv.acc.3

ggsave(filename = '../Figures/FigureS2B.pdf',p.eff.mv.acc.3,units = 'cm',width = 3,height = 3)
marginalConflictMVEffect <- function(model,x,newx) {
  poly.base <- poly(x,2)
  
  new_poly <- predict(poly.base,newx)
  
  coeffs.mv.1 <- summary(model)$coeff[,'Estimate']
  
  eff <- coeffs.mv.1['catChoiceConditionOR-XOR'] + 
    coeffs.mv.1['catChoiceConditionOR-XOR:poly(scaledMeanValue, 2)1']*new_poly[,1] + 
    coeffs.mv.1['catChoiceConditionOR-XOR:poly(scaledMeanValue, 2)2']*new_poly[,2]
  
  cov.mat <- vcov(model)
  
  eff.ci <- 1.96 * sqrt(cov.mat[2,2] + new_poly[,1]^2 * cov.mat[7,7] + new_poly[,2]^2 * cov.mat[8,8] + 
                                 2 * new_poly[,1] * cov.mat[2,7] + 2 * new_poly[,2] * cov.mat[2,8] + 
                                 2 * new_poly[,1] * new_poly[,2] * cov.mat[7,8])
  
  eff.df<-data.frame(x=newx,eff=eff,ci=eff.ci)
  
  return(eff.df)
}
new.mv.1 <- seq(quantile(df.total.rt.cfl.6$scaledMeanValue,0.025),
                quantile(df.total.rt.cfl.6$scaledMeanValue,0.975),0.1)

eff.df.mv.12 <- marginalConflictMVEffect(model.rating.cfl,
                                         df.total.rt.cfl.6$scaledMeanValue,
                                         new.mv.1) %>%
  dplyr::mutate(scaledMeanValue=x,
                catChoiceCondition='XOR - OR',
                fit=eff,
                upper=eff+ci,
                lower=eff-ci,
                se=NA,
                study='Study 12')

p.eff.cc.int.12<-ggplot(data=eff.df.mv.12, aes(x=x, y=fit)) + 
  geom_line(size=0.5)+theme_bw(12) +
  geom_ribbon(data=eff.df.mv.12, aes(x=x, max = upper, min = lower),alpha=0.3, inherit.aes = FALSE)+ 
  xlab("Overall value\n(z-scored)") + ylab('Effect of Inclusivity') +
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), plot.title = element_text(hjust = 0.5,size=6),
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black",size=0.2),strip.text.y = element_blank(),
        axis.ticks = element_line(colour = "black",size=0.2)) +
  theme(legend.justification=c(1,1),legend.position='none',text = element_text(size=6)) + geom_hline(yintercept=0,color='#555555',size=0.2) + #ggtitle('Conflict') +
  coord_cartesian(ylim=c(-1,0.1)) + scale_y_continuous(breaks = c(-1,0))

p.eff.cc.int.12

ggsave(filename = '../Figures/FigureS2C.pdf',p.eff.cc.int.12,units = 'cm',width = 3,height = 3)